home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2002 November / SGI IRIX Base Documentation 2002 November.iso / usr / share / catman / p_man / cat1 / flex.z / flex
Encoding:
Text File  |  2002-10-03  |  179.5 KB  |  3,697 lines

  1.  
  2.  
  3.  
  4.      FFFFLLLLEEEEXXXX((((1111))))             VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))              FFFFLLLLEEEEXXXX((((1111))))
  5.  
  6.  
  7.  
  8.      NNNNAAAAMMMMEEEE
  9.           flex - fast lexical analyzer generator
  10.  
  11.      SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  12.           fffflllleeeexxxx [[[[----bbbbccccddddffffhhhhiiiillllnnnnppppssssttttvvvvwwwwBBBBFFFFIIIILLLLTTTTVVVVXXXX77778888++++???? ----CCCC[[[[aaaaeeeeffffFFFFmmmmrrrr]]]] ----oooooooouuuuttttppppuuuutttt ----PPPPpppprrrreeeeffffiiiixxxx
  13.           ----SSSSsssskkkkeeeelllleeeettttoooonnnn]]]] [[[[--------hhhheeeellllpppp --------vvvveeeerrrrssssiiiioooonnnn --------ppppoooossssiiiixxxx----ccccoooommmmppppaaaatttt]]]] [_f_i_l_e_n_a_m_e ...]
  14.  
  15.      OOOOVVVVEEEERRRRVVVVIIIIEEEEWWWW
  16.           This manual describes _f_l_e_x, a tool for generating programs
  17.           that perform pattern-matching on text.  The manual includes
  18.           both tutorial and reference sections:
  19.  
  20.               Description
  21.                   a brief overview of the tool
  22.  
  23.               Some Simple Examples
  24.  
  25.               Format Of The Input File
  26.  
  27.               Patterns
  28.                   the extended regular expressions used by flex
  29.  
  30.               How The Input Is Matched
  31.                   the rules for determining what has been matched
  32.  
  33.               Actions
  34.                   how to specify what to do when a pattern is matched
  35.  
  36.               The Generated Scanner
  37.                   details regarding the scanner that flex produces;
  38.                   how to control the input source
  39.  
  40.               Start Conditions
  41.                   introducing context into your scanners, and
  42.                   managing "mini-scanners"
  43.  
  44.               Multiple Input Buffers
  45.                   how to manipulate multiple input sources; how to
  46.                   scan from strings instead of files
  47.  
  48.               End-of-file Rules
  49.                   special rules for matching the end of the input
  50.  
  51.               Miscellaneous Macros
  52.                   a summary of macros available to the actions
  53.  
  54.               Values Available To The User
  55.                   a summary of values available to the actions
  56.  
  57.               Interfacing With Yacc
  58.                   connecting flex scanners together with yacc parsers
  59.  
  60.  
  61.  
  62.  
  63.      Page 1                                          (printed 10/3/02)
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.      FFFFLLLLEEEEXXXX((((1111))))             VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))              FFFFLLLLEEEEXXXX((((1111))))
  71.  
  72.  
  73.  
  74.               Options
  75.                   flex command-line options, and the "%option"
  76.                   directive
  77.  
  78.               Performance Considerations
  79.                   how to make your scanner go as fast as possible
  80.  
  81.               Generating C++ Scanners
  82.                   the (experimental) facility for generating C++
  83.                   scanner classes
  84.  
  85.               Incompatibilities With Lex And POSIX
  86.                   how flex differs from AT&T lex and the POSIX lex
  87.                   standard
  88.  
  89.               Diagnostics
  90.                   those error messages produced by flex (or scanners
  91.                   it generates) whose meanings might not be apparent
  92.  
  93.               Files
  94.                   files used by flex
  95.  
  96.               Deficiencies / Bugs
  97.                   known problems with flex
  98.  
  99.               See Also
  100.                   other documentation, related tools
  101.  
  102.               Author
  103.                   includes contact information
  104.  
  105.  
  106.      DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  107.           _f_l_e_x is a tool for generating _s_c_a_n_n_e_r_s: programs which
  108.           recognized lexical patterns in text.  _f_l_e_x reads the given
  109.           input files, or its standard input if no file names are
  110.           given, for a description of a scanner to generate.  The
  111.           description is in the form of pairs of regular expressions
  112.           and C code, called _r_u_l_e_s. _f_l_e_x generates as output a C
  113.           source file, lllleeeexxxx....yyyyyyyy....cccc,,,, which defines a routine yyyyyyyylllleeeexxxx(((()))).... This
  114.           file is compiled and linked with the ----llllffffllll library to produce
  115.           an executable.  When the executable is run, it analyzes its
  116.           input for occurrences of the regular expressions.  Whenever
  117.           it finds one, it executes the corresponding C code.
  118.  
  119.      SSSSOOOOMMMMEEEE SSSSIIIIMMMMPPPPLLLLEEEE EEEEXXXXAAAAMMMMPPPPLLLLEEEESSSS
  120.           First some simple examples to get the flavor of how one uses
  121.           _f_l_e_x. The following _f_l_e_x input specifies a scanner which
  122.           whenever it encounters the string "username" will replace it
  123.           with the user's login name:
  124.  
  125.               %%
  126.  
  127.  
  128.  
  129.      Page 2                                          (printed 10/3/02)
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.      FFFFLLLLEEEEXXXX((((1111))))             VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))              FFFFLLLLEEEEXXXX((((1111))))
  137.  
  138.  
  139.  
  140.               username    printf( "%s", getlogin() );
  141.  
  142.           By default, any text not matched by a _f_l_e_x scanner is copied
  143.           to the output, so the net effect of this scanner is to copy
  144.           its input file to its output with each occurrence of
  145.           "username" expanded.  In this input, there is just one rule.
  146.           "username" is the _p_a_t_t_e_r_n and the "printf" is the _a_c_t_i_o_n.
  147.           The "%%" marks the beginning of the rules.
  148.  
  149.           Here's another simple example:
  150.  
  151.                       int num_lines = 0, num_chars = 0;
  152.  
  153.               %%
  154.               \n      ++num_lines; ++num_chars;
  155.               .       ++num_chars;
  156.  
  157.               %%
  158.               main()
  159.                       {
  160.                       yylex();
  161.                       printf( "# of lines = %d, # of chars = %d\n",
  162.                               num_lines, num_chars );
  163.                       }
  164.  
  165.           This scanner counts the number of characters and the number
  166.           of lines in its input (it produces no output other than the
  167.           final report on the counts).  The first line declares two
  168.           globals, "num_lines" and "num_chars", which are accessible
  169.           both inside yyyyyyyylllleeeexxxx(((()))) and in the mmmmaaaaiiiinnnn(((()))) routine declared after
  170.           the second "%%".  There are two rules, one which matches a
  171.           newline ("\n") and increments both the line count and the
  172.           character count, and one which matches any character other
  173.           than a newline (indicated by the "." regular expression).
  174.  
  175.           A somewhat more complicated example:
  176.  
  177.               /* scanner for a toy Pascal-like language */
  178.  
  179.               %{
  180.               /* need this for the call to atof() below */
  181.               #include <math.h>
  182.               %}
  183.  
  184.               DIGIT    [0-9]
  185.               ID       [a-z][a-z0-9]*
  186.  
  187.               %%
  188.  
  189.               {DIGIT}+    {
  190.                           printf( "An integer: %s (%d)\n", yytext,
  191.                                   atoi( yytext ) );
  192.  
  193.  
  194.  
  195.      Page 3                                          (printed 10/3/02)
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.      FFFFLLLLEEEEXXXX((((1111))))             VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))              FFFFLLLLEEEEXXXX((((1111))))
  203.  
  204.  
  205.  
  206.                           }
  207.  
  208.               {DIGIT}+"."{DIGIT}*        {
  209.                           printf( "A float: %s (%g)\n", yytext,
  210.                                   atof( yytext ) );
  211.                           }
  212.  
  213.               if|then|begin|end|procedure|function        {
  214.                           printf( "A keyword: %s\n", yytext );
  215.                           }
  216.  
  217.               {ID}        printf( "An identifier: %s\n", yytext );
  218.  
  219.               "+"|"-"|"*"|"/"   printf( "An operator: %s\n", yytext );
  220.  
  221.               "{"[^}\n]*"}"     /* eat up one-line comments */
  222.  
  223.               [ \t\n]+          /* eat up whitespace */
  224.  
  225.               .           printf( "Unrecognized character: %s\n", yytext );
  226.  
  227.               %%
  228.  
  229.               main( argc, argv )
  230.               int argc;
  231.               char **argv;
  232.                   {
  233.                   ++argv, --argc;  /* skip over program name */
  234.                   if ( argc > 0 )
  235.                           yyin = fopen( argv[0], "r" );
  236.                   else
  237.                           yyin = stdin;
  238.  
  239.                   yylex();
  240.                   }
  241.  
  242.           This is the beginnings of a simple scanner for a language
  243.           like Pascal.  It identifies different types of _t_o_k_e_n_s and
  244.           reports on what it has seen.
  245.  
  246.           The details of this example will be explained in the
  247.           following sections.
  248.  
  249.      FFFFOOOORRRRMMMMAAAATTTT OOOOFFFF TTTTHHHHEEEE IIIINNNNPPPPUUUUTTTT FFFFIIIILLLLEEEE
  250.           The _f_l_e_x input file consists of three sections, separated by
  251.           a line with just %%%%%%%% in it:
  252.  
  253.               definitions
  254.               %%
  255.               rules
  256.               %%
  257.               user code
  258.  
  259.  
  260.  
  261.      Page 4                                          (printed 10/3/02)
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.      FFFFLLLLEEEEXXXX((((1111))))             VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))              FFFFLLLLEEEEXXXX((((1111))))
  269.  
  270.  
  271.  
  272.           The _d_e_f_i_n_i_t_i_o_n_s section contains declarations of simple _n_a_m_e
  273.           definitions to simplify the scanner specification, and
  274.           declarations of _s_t_a_r_t _c_o_n_d_i_t_i_o_n_s, which are explained in a
  275.           later section.
  276.  
  277.           Name definitions have the form:
  278.  
  279.               name definition
  280.  
  281.           The "name" is a word beginning with a letter or an
  282.           underscore ('_') followed by zero or more letters, digits,
  283.           '_', or '-' (dash).  The definition is taken to begin at the
  284.           first non-white-space character following the name and
  285.           continuing to the end of the line.  The definition can
  286.           subsequently be referred to using "{name}", which will
  287.           expand to "(definition)".  For example,
  288.  
  289.               DIGIT    [0-9]
  290.               ID       [a-z][a-z0-9]*
  291.  
  292.           defines "DIGIT" to be a regular expression which matches a
  293.           single digit, and "ID" to be a regular expression which
  294.           matches a letter followed by zero-or-more letters-or-digits.
  295.           A subsequent reference to
  296.  
  297.               {DIGIT}+"."{DIGIT}*
  298.  
  299.           is identical to
  300.  
  301.               ([0-9])+"."([0-9])*
  302.  
  303.           and matches one-or-more digits followed by a '.' followed by
  304.           zero-or-more digits.
  305.  
  306.           The _r_u_l_e_s section of the _f_l_e_x input contains a series of
  307.           rules of the form:
  308.  
  309.               pattern   action
  310.  
  311.           where the pattern must be unindented and the action must
  312.           begin on the same line.
  313.  
  314.           See below for a further description of patterns and actions.
  315.  
  316.           Finally, the user code section is simply copied to lllleeeexxxx....yyyyyyyy....cccc
  317.           verbatim.  It is used for companion routines which call or
  318.           are called by the scanner.  The presence of this section is
  319.           optional; if it is missing, the second %%%%%%%% in the input file
  320.           may be skipped, too.
  321.  
  322.           In the definitions and rules sections, any _i_n_d_e_n_t_e_d text or
  323.           text enclosed in %%%%{{{{ and %%%%}}}} is copied verbatim to the output
  324.  
  325.  
  326.  
  327.      Page 5                                          (printed 10/3/02)
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.      FFFFLLLLEEEEXXXX((((1111))))             VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))              FFFFLLLLEEEEXXXX((((1111))))
  335.  
  336.  
  337.  
  338.           (with the %{}'s removed).  The %{}'s must appear unindented
  339.           on lines by themselves.
  340.  
  341.           In the rules section, any indented or %{} text appearing
  342.           before the first rule may be used to declare variables which
  343.           are local to the scanning routine and (after the
  344.           declarations) code which is to be executed whenever the
  345.           scanning routine is entered.  Other indented or %{} text in
  346.           the rule section is still copied to the output, but its
  347.           meaning is not well-defined and it may well cause compile-
  348.           time errors (this feature is present for _P_O_S_I_X compliance;
  349.           see below for other such features).
  350.  
  351.           In the definitions section (but not in the rules section),
  352.           an unindented comment (i.e., a line beginning with "/*") is
  353.           also copied verbatim to the output up to the next "*/".
  354.  
  355.      PPPPAAAATTTTTTTTEEEERRRRNNNNSSSS
  356.           The patterns in the input are written using an extended set
  357.           of regular expressions.  These are:
  358.  
  359.               x          match the character 'x'
  360.               .          any character (byte) except newline
  361.               [xyz]      a "character class"; in this case, the pattern
  362.                            matches either an 'x', a 'y', or a 'z'
  363.               [abj-oZ]   a "character class" with a range in it; matches
  364.                            an 'a', a 'b', any letter from 'j' through 'o',
  365.                            or a 'Z'
  366.               [^A-Z]     a "negated character class", i.e., any character
  367.                            but those in the class.  In this case, any
  368.                            character EXCEPT an uppercase letter.
  369.               [^A-Z\n]   any character EXCEPT an uppercase letter or
  370.                            a newline
  371.               r*         zero or more r's, where r is any regular expression
  372.               r+         one or more r's
  373.               r?         zero or one r's (that is, "an optional r")
  374.               r{2,5}     anywhere from two to five r's
  375.               r{2,}      two or more r's
  376.               r{4}       exactly 4 r's
  377.               {name}     the expansion of the "name" definition
  378.                          (see above)
  379.               "[xyz]\"foo"
  380.                          the literal string: [xyz]"foo
  381.               \X         if X is an 'a', 'b', 'f', 'n', 'r', 't', or 'v',
  382.                            then the ANSI-C interpretation of \x.
  383.                            Otherwise, a literal 'X' (used to escape
  384.                            operators such as '*')
  385.               \0         a NUL character (ASCII code 0)
  386.               \123       the character with octal value 123
  387.               \x2a       the character with hexadecimal value 2a
  388.               (r)        match an r; parentheses are used to override
  389.                            precedence (see below)
  390.  
  391.  
  392.  
  393.      Page 6                                          (printed 10/3/02)
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.      FFFFLLLLEEEEXXXX((((1111))))             VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))              FFFFLLLLEEEEXXXX((((1111))))
  401.  
  402.  
  403.  
  404.               rs         the regular expression r followed by the
  405.                            regular expression s; called "concatenation"
  406.  
  407.  
  408.               r|s        either an r or an s
  409.  
  410.  
  411.               r/s        an r but only if it is followed by an s.  The
  412.                            text matched by s is included when determining
  413.                            whether this rule is the "longest match",
  414.                            but is then returned to the input before
  415.                            the action is executed.  So the action only
  416.                            sees the text matched by r.  This type
  417.                            of pattern is called trailing context".
  418.                            (There are some combinations of r/s that flex
  419.                            cannot match correctly; see notes in the
  420.                            Deficiencies / Bugs section below regarding
  421.                            "dangerous trailing context".)
  422.               ^r         an r, but only at the beginning of a line (i.e.,
  423.                            which just starting to scan, or right after a
  424.                            newline has been scanned).
  425.               r$         an r, but only at the end of a line (i.e., just
  426.                            before a newline).  Equivalent to "r/\n".
  427.  
  428.                          Note that flex's notion of "newline" is exactly
  429.                          whatever the C compiler used to compile flex
  430.                          interprets '\n' as; in particular, on some DOS
  431.                          systems you must either filter out \r's in the
  432.                          input yourself, or explicitly use r/\r\n for "r$".
  433.  
  434.  
  435.               <s>r       an r, but only in start condition s (see
  436.                            below for discussion of start conditions)
  437.               <s1,s2,s3>r
  438.                          same, but in any of start conditions s1,
  439.                            s2, or s3
  440.               <*>r       an r in any start condition, even an exclusive one.
  441.  
  442.  
  443.               <<EOF>>    an end-of-file
  444.               <s1,s2><<EOF>>
  445.                          an end-of-file when in start condition s1 or s2
  446.  
  447.           Note that inside of a character class, all regular
  448.           expression operators lose their special meaning except
  449.           escape ('\') and the character class operators, '-', ']',
  450.           and, at the beginning of the class, '^'.
  451.  
  452.           The regular expressions listed above are grouped according
  453.           to precedence, from highest precedence at the top to lowest
  454.           at the bottom.  Those grouped together have equal precedence
  455.           (see special note on the precedence of the repeat operator,
  456.  
  457.  
  458.  
  459.      Page 7                                          (printed 10/3/02)
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466.      FFFFLLLLEEEEXXXX((((1111))))             VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))              FFFFLLLLEEEEXXXX((((1111))))
  467.  
  468.  
  469.  
  470.           {{{{}}}}, under the documentation for the --------ppppoooossssiiiixxxx----ccccoooommmmppppaaaatttt POSIX
  471.           compliance option).  For example,
  472.  
  473.               foo|bar*
  474.  
  475.           is the same as
  476.  
  477.               (foo)|(ba(r*))
  478.  
  479.           since the '*' operator has higher precedence than
  480.           concatenation, and concatenation higher than alternation
  481.           ('|').  This pattern therefore matches _e_i_t_h_e_r the string
  482.           "foo" _o_r the string "ba" followed by zero-or-more r's.  To
  483.           match "foo" or zero-or-more "bar"'s, use:
  484.  
  485.               foo|(bar)*
  486.  
  487.           and to match zero-or-more "foo"'s-or-"bar"'s:
  488.  
  489.               (foo|bar)*
  490.  
  491.  
  492.           In addition to characters and ranges of characters,
  493.           character classes can also contain character class
  494.           _e_x_p_r_e_s_s_i_o_n_s. These are expressions enclosed inside [[[[:::: and ::::]]]]
  495.           delimiters (which themselves must appear between the '[' and
  496.           ']' of the character class; other elements may occur inside
  497.           the character class, too).  The valid expressions are:
  498.  
  499.               [:alnum:] [:alpha:] [:blank:]
  500.               [:cntrl:] [:digit:] [:graph:]
  501.               [:lower:] [:print:] [:punct:]
  502.               [:space:] [:upper:] [:xdigit:]
  503.  
  504.           These expressions all designate a set of characters
  505.           equivalent to the corresponding standard C iiiissssXXXXXXXXXXXX function.
  506.           For example, [[[[::::aaaallllnnnnuuuummmm::::]]]] designates those characters for which
  507.           iiiissssaaaallllnnnnuuuummmm(((()))) returns true - i.e., any alphabetic or numeric.
  508.           Some systems don't provide iiiissssbbbbllllaaaannnnkkkk(((()))),,,, so flex defines
  509.           [[[[::::bbbbllllaaaannnnkkkk::::]]]] as a blank or a tab.
  510.  
  511.           For example, the following character classes are all
  512.           equivalent:
  513.  
  514.               [[:alnum:]]
  515.               [[:alpha:][:digit:]
  516.               [[:alpha:]0-9]
  517.               [a-zA-Z0-9]
  518.  
  519.           If your scanner is case-insensitive (the ----iiii flag), then
  520.           [[[[::::uuuuppppppppeeeerrrr::::]]]] and [[[[::::lllloooowwwweeeerrrr::::]]]] are equivalent to [[[[::::aaaallllpppphhhhaaaa::::]]]]....
  521.  
  522.  
  523.  
  524.  
  525.      Page 8                                          (printed 10/3/02)
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.      FFFFLLLLEEEEXXXX((((1111))))             VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))              FFFFLLLLEEEEXXXX((((1111))))
  533.  
  534.  
  535.  
  536.           Some notes on patterns:
  537.  
  538.           -    A negated character class such as the example "[^A-Z]"
  539.                above _w_i_l_l _m_a_t_c_h _a _n_e_w_l_i_n_e unless "\n" (or an
  540.                equivalent escape sequence) is one of the characters
  541.                explicitly present in the negated character class
  542.                (e.g., "[^A-Z\n]").  This is unlike how many other
  543.                regular expression tools treat negated character
  544.                classes, but unfortunately the inconsistency is
  545.                historically entrenched.  Matching newlines means that
  546.                a pattern like [^"]* can match the entire input unless
  547.                there's another quote in the input.
  548.  
  549.           -    A rule can have at most one instance of trailing
  550.                context (the '/' operator or the '$' operator).  The
  551.                start condition, '^', and "<<EOF>>" patterns can only
  552.                occur at the beginning of a pattern, and, as well as
  553.                with '/' and '$', cannot be grouped inside parentheses.
  554.                A '^' which does not occur at the beginning of a rule
  555.                or a '$' which does not occur at the end of a rule
  556.                loses its special properties and is treated as a normal
  557.                character.
  558.  
  559.                The following are illegal:
  560.  
  561.                    foo/bar$
  562.                    <sc1>foo<sc2>bar
  563.  
  564.                Note that the first of these, can be written
  565.                "foo/bar\n".
  566.  
  567.                The following will result in '$' or '^' being treated
  568.                as a normal character:
  569.  
  570.                    foo|(bar$)
  571.                    foo|^bar
  572.  
  573.                If what's wanted is a "foo" or a bar-followed-by-a-
  574.                newline, the following could be used (the special '|'
  575.                action is explained below):
  576.  
  577.                    foo      |
  578.                    bar$     /* action goes here */
  579.  
  580.                A similar trick will work for matching a foo or a bar-
  581.                at-the-beginning-of-a-line.
  582.  
  583.      HHHHOOOOWWWW TTTTHHHHEEEE IIIINNNNPPPPUUUUTTTT IIIISSSS MMMMAAAATTTTCCCCHHHHEEEEDDDD
  584.           When the generated scanner is run, it analyzes its input
  585.           looking for strings which match any of its patterns.  If it
  586.           finds more than one match, it takes the one matching the
  587.           most text (for trailing context rules, this includes the
  588.  
  589.  
  590.  
  591.      Page 9                                          (printed 10/3/02)
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598.      FFFFLLLLEEEEXXXX((((1111))))             VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))              FFFFLLLLEEEEXXXX((((1111))))
  599.  
  600.  
  601.  
  602.           length of the trailing part, even though it will then be
  603.           returned to the input).  If it finds two or more matches of
  604.           the same length, the rule listed first in the _f_l_e_x input
  605.           file is chosen.
  606.  
  607.           Once the match is determined, the text corresponding to the
  608.           match (called the _t_o_k_e_n) is made available in the global
  609.           character pointer yyyyyyyytttteeeexxxxtttt,,,, and its length in the global
  610.           integer yyyyyyyylllleeeennnngggg.... The _a_c_t_i_o_n corresponding to the matched
  611.           pattern is then executed (a more detailed description of
  612.           actions follows), and then the remaining input is scanned
  613.           for another match.
  614.  
  615.           If no match is found, then the _d_e_f_a_u_l_t _r_u_l_e is executed: the
  616.           next character in the input is considered matched and copied
  617.           to the standard output.  Thus, the simplest legal _f_l_e_x input
  618.           is:
  619.  
  620.               %%
  621.  
  622.           which generates a scanner that simply copies its input (one
  623.           character at a time) to its output.
  624.  
  625.           Note that yyyyyyyytttteeeexxxxtttt can be defined in two different ways:
  626.           either as a character _p_o_i_n_t_e_r or as a character _a_r_r_a_y. You
  627.           can control which definition _f_l_e_x uses by including one of
  628.           the special directives %%%%ppppooooiiiinnnntttteeeerrrr or %%%%aaaarrrrrrrraaaayyyy in the first
  629.           (definitions) section of your flex input.  The default is
  630.           %%%%ppppooooiiiinnnntttteeeerrrr,,,, unless you use the ----llll lex compatibility option, in
  631.           which case yyyyyyyytttteeeexxxxtttt will be an array.  The advantage of using
  632.           %%%%ppppooooiiiinnnntttteeeerrrr is substantially faster scanning and no buffer
  633.           overflow when matching very large tokens (unless you run out
  634.           of dynamic memory).  The disadvantage is that you are
  635.           restricted in how your actions can modify yyyyyyyytttteeeexxxxtttt (see the
  636.           next section), and calls to the uuuunnnnppppuuuutttt(((()))) function destroys
  637.           the present contents of yyyyyyyytttteeeexxxxtttt,,,, which can be a considerable
  638.           porting headache when moving between different _l_e_x versions.
  639.  
  640.           The advantage of %%%%aaaarrrrrrrraaaayyyy is that you can then modify yyyyyyyytttteeeexxxxtttt
  641.           to your heart's content, and calls to uuuunnnnppppuuuutttt(((()))) do not destroy
  642.           yyyyyyyytttteeeexxxxtttt (see below).  Furthermore, existing _l_e_x programs
  643.           sometimes access yyyyyyyytttteeeexxxxtttt externally using declarations of the
  644.           form:
  645.               extern char yytext[];
  646.           This definition is erroneous when used with %%%%ppppooooiiiinnnntttteeeerrrr,,,, but
  647.           correct for %%%%aaaarrrrrrrraaaayyyy....
  648.  
  649.           %%%%aaaarrrrrrrraaaayyyy defines yyyyyyyytttteeeexxxxtttt to be an array of YYYYYYYYLLLLMMMMAAAAXXXX characters,
  650.           which defaults to a fairly large value.  You can change the
  651.           size by simply #define'ing YYYYYYYYLLLLMMMMAAAAXXXX to a different value in
  652.           the first section of your _f_l_e_x input.  As mentioned above,
  653.           with %%%%ppppooooiiiinnnntttteeeerrrr yytext grows dynamically to accommodate large
  654.  
  655.  
  656.  
  657.      Page 10                                         (printed 10/3/02)
  658.  
  659.  
  660.  
  661.  
  662.  
  663.  
  664.      FFFFLLLLEEEEXXXX((((1111))))             VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))              FFFFLLLLEEEEXXXX((((1111))))
  665.  
  666.  
  667.  
  668.           tokens.  While this means your %%%%ppppooooiiiinnnntttteeeerrrr scanner can
  669.           accommodate very large tokens (such as matching entire
  670.           blocks of comments), bear in mind that each time the scanner
  671.           must resize yyyyyyyytttteeeexxxxtttt it also must rescan the entire token from
  672.           the beginning, so matching such tokens can prove slow.
  673.           yyyyyyyytttteeeexxxxtttt presently does _n_o_t dynamically grow if a call to
  674.           uuuunnnnppppuuuutttt(((()))) results in too much text being pushed back; instead,
  675.           a run-time error results.
  676.  
  677.           Also note that you cannot use %%%%aaaarrrrrrrraaaayyyy with C++ scanner
  678.           classes (the cccc++++++++ option; see below).
  679.  
  680.      AAAACCCCTTTTIIIIOOOONNNNSSSS
  681.           Each pattern in a rule has a corresponding action, which can
  682.           be any arbitrary C statement.  The pattern ends at the first
  683.           non-escaped whitespace character; the remainder of the line
  684.           is its action.  If the action is empty, then when the
  685.           pattern is matched the input token is simply discarded.  For
  686.           example, here is the specification for a program which
  687.           deletes all occurrences of "zap me" from its input:
  688.  
  689.               %%
  690.               "zap me"
  691.  
  692.           (It will copy all other characters in the input to the
  693.           output since they will be matched by the default rule.)
  694.  
  695.           Here is a program which compresses multiple blanks and tabs
  696.           down to a single blank, and throws away whitespace found at
  697.           the end of a line:
  698.  
  699.               %%
  700.               [ \t]+        putchar( ' ' );
  701.               [ \t]+$       /* ignore this token */
  702.  
  703.  
  704.           If the action contains a '{', then the action spans till the
  705.           balancing '}' is found, and the action may cross multiple
  706.           lines.  _f_l_e_x knows about C strings and comments and won't be
  707.           fooled by braces found within them, but also allows actions
  708.           to begin with %%%%{{{{ and will consider the action to be all the
  709.           text up to the next %%%%}}}} (regardless of ordinary braces inside
  710.           the action).
  711.  
  712.           An action consisting solely of a vertical bar ('|') means
  713.           "same as the action for the next rule."  See below for an
  714.           illustration.
  715.  
  716.           Actions can include arbitrary C code, including rrrreeeettttuuuurrrrnnnn
  717.           statements to return a value to whatever routine called
  718.           yyyyyyyylllleeeexxxx(((()))).... Each time yyyyyyyylllleeeexxxx(((()))) is called it continues processing
  719.           tokens from where it last left off until it either reaches
  720.  
  721.  
  722.  
  723.      Page 11                                         (printed 10/3/02)
  724.  
  725.  
  726.  
  727.  
  728.  
  729.  
  730.      FFFFLLLLEEEEXXXX((((1111))))             VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))              FFFFLLLLEEEEXXXX((((1111))))
  731.  
  732.  
  733.  
  734.           the end of the file or executes a return.
  735.  
  736.           Actions are free to modify yyyyyyyytttteeeexxxxtttt except for lengthening it
  737.           (adding characters to its end--these will overwrite later
  738.           characters in the input stream).  This however does not
  739.           apply when using %%%%aaaarrrrrrrraaaayyyy (see above); in that case, yyyyyyyytttteeeexxxxtttt
  740.           may be freely modified in any way.
  741.  
  742.           Actions are free to modify yyyyyyyylllleeeennnngggg except they should not do
  743.           so if the action also includes use of yyyyyyyymmmmoooorrrreeee(((()))) (see below).
  744.  
  745.           There are a number of special directives which can be
  746.           included within an action:
  747.  
  748.           -    EEEECCCCHHHHOOOO copies yytext to the scanner's output.
  749.  
  750.           -    BBBBEEEEGGGGIIIINNNN followed by the name of a start condition places
  751.                the scanner in the corresponding start condition (see
  752.                below).
  753.  
  754.           -    RRRREEEEJJJJEEEECCCCTTTT directs the scanner to proceed on to the "second
  755.                best" rule which matched the input (or a prefix of the
  756.                input).  The rule is chosen as described above in "How
  757.                the Input is Matched", and yyyyyyyytttteeeexxxxtttt and yyyyyyyylllleeeennnngggg set up
  758.                appropriately.  It may either be one which matched as
  759.                much text as the originally chosen rule but came later
  760.                in the _f_l_e_x input file, or one which matched less text.
  761.                For example, the following will both count the words in
  762.                the input and call the routine special() whenever
  763.                "frob" is seen:
  764.  
  765.                            int word_count = 0;
  766.                    %%
  767.  
  768.                    frob        special(); REJECT;
  769.                    [^ \t\n]+   ++word_count;
  770.  
  771.                Without the RRRREEEEJJJJEEEECCCCTTTT,,,, any "frob"'s in the input would not
  772.                be counted as words, since the scanner normally
  773.                executes only one action per token.  Multiple RRRREEEEJJJJEEEECCCCTTTT''''ssss
  774.                are allowed, each one finding the next best choice to
  775.                the currently active rule.  For example, when the
  776.                following scanner scans the token "abcd", it will write
  777.                "abcdabcaba" to the output:
  778.  
  779.                    %%
  780.                    a        |
  781.                    ab       |
  782.                    abc      |
  783.                    abcd     ECHO; REJECT;
  784.                    .|\n     /* eat up any unmatched character */
  785.  
  786.  
  787.  
  788.  
  789.      Page 12                                         (printed 10/3/02)
  790.  
  791.  
  792.  
  793.  
  794.  
  795.  
  796.      FFFFLLLLEEEEXXXX((((1111))))             VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))              FFFFLLLLEEEEXXXX((((1111))))
  797.  
  798.  
  799.  
  800.                (The first three rules share the fourth's action since
  801.                they use the special '|' action.)  RRRREEEEJJJJEEEECCCCTTTT is a
  802.                particularly expensive feature in terms of scanner
  803.                performance; if it is used in _a_n_y of the scanner's
  804.                actions it will slow down _a_l_l of the scanner's
  805.                matching.  Furthermore, RRRREEEEJJJJEEEECCCCTTTT cannot be used with the
  806.                -_C_f or -_C_F options (see below).
  807.  
  808.                Note also that unlike the other special actions, RRRREEEEJJJJEEEECCCCTTTT
  809.                is a _b_r_a_n_c_h; code immediately following it in the
  810.                action will _n_o_t be executed.
  811.  
  812.           -    yyyyyyyymmmmoooorrrreeee(((()))) tells the scanner that the next time it
  813.                matches a rule, the corresponding token should be
  814.                _a_p_p_e_n_d_e_d onto the current value of yyyyyyyytttteeeexxxxtttt rather than
  815.                replacing it.  For example, given the input "mega-
  816.                kludge" the following will write "mega-mega-kludge" to
  817.                the output:
  818.  
  819.                    %%
  820.                    mega-    ECHO; yymore();
  821.                    kludge   ECHO;
  822.  
  823.                First "mega-" is matched and echoed to the output.
  824.                Then "kludge" is matched, but the previous "mega-" is
  825.                still hanging around at the beginning of yyyyyyyytttteeeexxxxtttt so the
  826.                EEEECCCCHHHHOOOO for the "kludge" rule will actually write "mega-
  827.                kludge".
  828.  
  829.           Two notes regarding use of yyyyyyyymmmmoooorrrreeee(((()))).... First, yyyyyyyymmmmoooorrrreeee(((()))) depends
  830.           on the value of _y_y_l_e_n_g correctly reflecting the size of the
  831.           current token, so you must not modify _y_y_l_e_n_g if you are
  832.           using yyyyyyyymmmmoooorrrreeee(((()))).... Second, the presence of yyyyyyyymmmmoooorrrreeee(((()))) in the
  833.           scanner's action entails a minor performance penalty in the
  834.           scanner's matching speed.
  835.  
  836.           -    yyyyyyyylllleeeessssssss((((nnnn)))) returns all but the first _n characters of the
  837.                current token back to the input stream, where they will
  838.                be rescanned when the scanner looks for the next match.
  839.                yyyyyyyytttteeeexxxxtttt and yyyyyyyylllleeeennnngggg are adjusted appropriately (e.g.,
  840.                yyyyyyyylllleeeennnngggg will now be equal to _n ).  For example, on the
  841.                input "foobar" the following will write out
  842.                "foobarbar":
  843.  
  844.                    %%
  845.                    foobar    ECHO; yyless(3);
  846.                    [a-z]+    ECHO;
  847.  
  848.                An argument of 0 to yyyyyyyylllleeeessssssss will cause the entire
  849.                current input string to be scanned again.  Unless
  850.                you've changed how the scanner will subsequently
  851.                process its input (using BBBBEEEEGGGGIIIINNNN,,,, for example), this will
  852.  
  853.  
  854.  
  855.      Page 13                                         (printed 10/3/02)
  856.  
  857.  
  858.  
  859.  
  860.  
  861.  
  862.      FFFFLLLLEEEEXXXX((((1111))))             VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))              FFFFLLLLEEEEXXXX((((1111))))
  863.  
  864.  
  865.  
  866.                result in an endless loop.
  867.  
  868.           Note that yyyyyyyylllleeeessssssss is a macro and can only be used in the flex
  869.           input file, not from other source files.
  870.  
  871.           -    uuuunnnnppppuuuutttt((((cccc)))) puts the character _c back onto the input
  872.                stream.  It will be the next character scanned.  The
  873.                following action will take the current token and cause
  874.                it to be rescanned enclosed in parentheses.
  875.  
  876.                    {
  877.                    int i;
  878.                    /* Copy yytext because unput() trashes yytext */
  879.                    char *yycopy = strdup( yytext );
  880.                    unput( ')' );
  881.                    for ( i = yyleng - 1; i >= 0; --i )
  882.                        unput( yycopy[i] );
  883.                    unput( '(' );
  884.                    free( yycopy );
  885.                    }
  886.  
  887.                Note that since each uuuunnnnppppuuuutttt(((()))) puts the given character
  888.                back at the _b_e_g_i_n_n_i_n_g of the input stream, pushing back
  889.                strings must be done back-to-front.
  890.  
  891.           An important potential problem when using uuuunnnnppppuuuutttt(((()))) is that if
  892.           you are using %%%%ppppooooiiiinnnntttteeeerrrr (the default), a call to uuuunnnnppppuuuutttt(((())))
  893.           _d_e_s_t_r_o_y_s the contents of _y_y_t_e_x_t, starting with its rightmost
  894.           character and devouring one character to the left with each
  895.           call.  If you need the value of yytext preserved after a
  896.           call to uuuunnnnppppuuuutttt(((()))) (as in the above example), you must either
  897.           first copy it elsewhere, or build your scanner using %%%%aaaarrrrrrrraaaayyyy
  898.           instead (see How The Input Is Matched).
  899.  
  900.           Finally, note that you cannot put back EEEEOOOOFFFF to attempt to
  901.           mark the input stream with an end-of-file.
  902.  
  903.           -    iiiinnnnppppuuuutttt(((()))) reads the next character from the input stream.
  904.                For example, the following is one way to eat up C
  905.                comments:
  906.  
  907.                    %%
  908.                    "/*"        {
  909.                                register int c;
  910.  
  911.                                for ( ; ; )
  912.                                    {
  913.                                    while ( (c = input()) != '*' &&
  914.                                            c != EOF )
  915.                                        ;    /* eat up text of comment */
  916.  
  917.                                    if ( c == '*' )
  918.  
  919.  
  920.  
  921.      Page 14                                         (printed 10/3/02)
  922.  
  923.  
  924.  
  925.  
  926.  
  927.  
  928.      FFFFLLLLEEEEXXXX((((1111))))             VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))              FFFFLLLLEEEEXXXX((((1111))))
  929.  
  930.  
  931.  
  932.                                        {
  933.                                        while ( (c = input()) == '*' )
  934.                                            ;
  935.                                        if ( c == '/' )
  936.                                            break;    /* found the end */
  937.                                        }
  938.  
  939.                                    if ( c == EOF )
  940.                                        {
  941.                                        error( "EOF in comment" );
  942.                                        break;
  943.                                        }
  944.                                    }
  945.                                }
  946.  
  947.                (Note that if the scanner is compiled using CCCC++++++++,,,, then
  948.                iiiinnnnppppuuuutttt(((()))) is instead referred to as yyyyyyyyiiiinnnnppppuuuutttt(((()))),,,, in order
  949.                to avoid a name clash with the CCCC++++++++ stream by the name
  950.                of _i_n_p_u_t.)
  951.  
  952.           -    YYYYYYYY____FFFFLLLLUUUUSSSSHHHH____BBBBUUUUFFFFFFFFEEEERRRR flushes the scanner's internal buffer
  953.                so that the next time the scanner attempts to match a
  954.                token, it will first refill the buffer using YYYYYYYY____IIIINNNNPPPPUUUUTTTT
  955.                (see The Generated Scanner, below).  This action is a
  956.                special case of the more general yyyyyyyy____fffflllluuuusssshhhh____bbbbuuuuffffffffeeeerrrr(((())))
  957.                function, described below in the section Multiple Input
  958.                Buffers.
  959.  
  960.           -    yyyyyyyytttteeeerrrrmmmmiiiinnnnaaaatttteeee(((()))) can be used in lieu of a return statement
  961.                in an action.  It terminates the scanner and returns a
  962.                0 to the scanner's caller, indicating "all done".  By
  963.                default, yyyyyyyytttteeeerrrrmmmmiiiinnnnaaaatttteeee(((()))) is also called when an end-of-
  964.                file is encountered.  It is a macro and may be
  965.                redefined.
  966.  
  967.      TTTTHHHHEEEE GGGGEEEENNNNEEEERRRRAAAATTTTEEEEDDDD SSSSCCCCAAAANNNNNNNNEEEERRRR
  968.           The output of _f_l_e_x is the file lllleeeexxxx....yyyyyyyy....cccc,,,, which contains the
  969.           scanning routine yyyyyyyylllleeeexxxx(((()))),,,, a number of tables used by it for
  970.           matching tokens, and a number of auxiliary routines and
  971.           macros.  By default, yyyyyyyylllleeeexxxx(((()))) is declared as follows:
  972.  
  973.               int yylex()
  974.                   {
  975.                   ... various definitions and the actions in here ...
  976.                   }
  977.  
  978.           (If your environment supports function prototypes, then it
  979.           will be "int yylex( void )".)  This definition may be
  980.           changed by defining the "YY_DECL" macro.  For example, you
  981.           could use:
  982.  
  983.               #define YY_DECL float lexscan( a, b ) float a, b;
  984.  
  985.  
  986.  
  987.      Page 15                                         (printed 10/3/02)
  988.  
  989.  
  990.  
  991.  
  992.  
  993.  
  994.      FFFFLLLLEEEEXXXX((((1111))))             VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))              FFFFLLLLEEEEXXXX((((1111))))
  995.  
  996.  
  997.  
  998.           to give the scanning routine the name _l_e_x_s_c_a_n, returning a
  999.           float, and taking two floats as arguments.  Note that if you
  1000.           give arguments to the scanning routine using a K&R-
  1001.           style/non-prototyped function declaration, you must
  1002.           terminate the definition with a semi-colon (;).
  1003.  
  1004.           Whenever yyyyyyyylllleeeexxxx(((()))) is called, it scans tokens from the global
  1005.           input file _y_y_i_n (which defaults to stdin).  It continues
  1006.           until it either reaches an end-of-file (at which point it
  1007.           returns the value 0) or one of its actions executes a _r_e_t_u_r_n
  1008.           statement.
  1009.  
  1010.           If the scanner reaches an end-of-file, subsequent calls are
  1011.           undefined unless either _y_y_i_n is pointed at a new input file
  1012.           (in which case scanning continues from that file), or
  1013.           yyyyyyyyrrrreeeessssttttaaaarrrrtttt(((()))) is called.  yyyyyyyyrrrreeeessssttttaaaarrrrtttt(((()))) takes one argument, a
  1014.           FFFFIIIILLLLEEEE **** pointer (which can be nil, if you've set up YYYYYYYY____IIIINNNNPPPPUUUUTTTT
  1015.           to scan from a source other than _y_y_i_n), and initializes _y_y_i_n
  1016.           for scanning from that file.  Essentially there is no
  1017.           difference between just assigning _y_y_i_n to a new input file
  1018.           or using yyyyyyyyrrrreeeessssttttaaaarrrrtttt(((()))) to do so; the latter is available for
  1019.           compatibility with previous versions of _f_l_e_x, and because it
  1020.           can be used to switch input files in the middle of scanning.
  1021.           It can also be used to throw away the current input buffer,
  1022.           by calling it with an argument of _y_y_i_n; but better is to use
  1023.           YYYYYYYY____FFFFLLLLUUUUSSSSHHHH____BBBBUUUUFFFFFFFFEEEERRRR (see above).  Note that yyyyyyyyrrrreeeessssttttaaaarrrrtttt(((()))) does _n_o_t
  1024.           reset the start condition to IIIINNNNIIIITTTTIIIIAAAALLLL (see Start Conditions,
  1025.           below).
  1026.  
  1027.           If yyyyyyyylllleeeexxxx(((()))) stops scanning due to executing a _r_e_t_u_r_n
  1028.           statement in one of the actions, the scanner may then be
  1029.           called again and it will resume scanning where it left off.
  1030.  
  1031.           By default (and for purposes of efficiency), the scanner
  1032.           uses block-reads rather than simple _g_e_t_c() calls to read
  1033.           characters from _y_y_i_n. The nature of how it gets its input
  1034.           can be controlled by defining the YYYYYYYY____IIIINNNNPPPPUUUUTTTT macro.
  1035.           YY_INPUT's calling sequence is
  1036.           "YY_INPUT(buf,result,max_size)".  Its action is to place up
  1037.           to _m_a_x__s_i_z_e characters in the character array _b_u_f and return
  1038.           in the integer variable _r_e_s_u_l_t either the number of
  1039.           characters read or the constant YY_NULL (0 on Unix systems)
  1040.           to indicate EOF.  The default YY_INPUT reads from the global
  1041.           file-pointer "yyin".
  1042.  
  1043.           A sample definition of YY_INPUT (in the definitions section
  1044.           of the input file):
  1045.  
  1046.               %{
  1047.               #define YY_INPUT(buf,result,max_size) \
  1048.                   { \
  1049.                   int c = getchar(); \
  1050.  
  1051.  
  1052.  
  1053.      Page 16                                         (printed 10/3/02)
  1054.  
  1055.  
  1056.  
  1057.  
  1058.  
  1059.  
  1060.      FFFFLLLLEEEEXXXX((((1111))))             VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))              FFFFLLLLEEEEXXXX((((1111))))
  1061.  
  1062.  
  1063.  
  1064.                   result = (c == EOF) ? YY_NULL : (buf[0] = c, 1); \
  1065.                   }
  1066.               %}
  1067.  
  1068.           This definition will change the input processing to occur
  1069.           one character at a time.
  1070.  
  1071.           When the scanner receives an end-of-file indication from
  1072.           YY_INPUT, it then checks the yyyyyyyywwwwrrrraaaapppp(((()))) function.  If yyyyyyyywwwwrrrraaaapppp(((())))
  1073.           returns false (zero), then it is assumed that the function
  1074.           has gone ahead and set up _y_y_i_n to point to another input
  1075.           file, and scanning continues.  If it returns true (non-
  1076.           zero), then the scanner terminates, returning 0 to its
  1077.           caller.  Note that in either case, the start condition
  1078.           remains unchanged; it does _n_o_t revert to IIIINNNNIIIITTTTIIIIAAAALLLL....
  1079.  
  1080.           If you do not supply your own version of yyyyyyyywwwwrrrraaaapppp(((()))),,,, then you
  1081.           must either use %%%%ooooppppttttiiiioooonnnn nnnnooooyyyyyyyywwwwrrrraaaapppp (in which case the scanner
  1082.           behaves as though yyyyyyyywwwwrrrraaaapppp(((()))) returned 1), or you must link
  1083.           with ----llllffffllll to obtain the default version of the routine,
  1084.           which always returns 1.
  1085.  
  1086.           Three routines are available for scanning from in-memory
  1087.           buffers rather than files:  yyyyyyyy____ssssccccaaaannnn____ssssttttrrrriiiinnnngggg(((()))),,,,
  1088.           yyyyyyyy____ssssccccaaaannnn____bbbbyyyytttteeeessss(((()))),,,, and yyyyyyyy____ssssccccaaaannnn____bbbbuuuuffffffffeeeerrrr(((()))).... See the discussion of
  1089.           them below in the section Multiple Input Buffers.
  1090.  
  1091.           The scanner writes its EEEECCCCHHHHOOOO output to the _y_y_o_u_t global
  1092.           (default, stdout), which may be redefined by the user simply
  1093.           by assigning it to some other FFFFIIIILLLLEEEE pointer.
  1094.  
  1095.      SSSSTTTTAAAARRRRTTTT CCCCOOOONNNNDDDDIIIITTTTIIIIOOOONNNNSSSS
  1096.           _f_l_e_x provides a mechanism for conditionally activating
  1097.           rules.  Any rule whose pattern is prefixed with "<sc>" will
  1098.           only be active when the scanner is in the start condition
  1099.           named "sc".  For example,
  1100.  
  1101.               <STRING>[^"]*        { /* eat up the string body ... */
  1102.                           ...
  1103.                           }
  1104.  
  1105.           will be active only when the scanner is in the "STRING"
  1106.           start condition, and
  1107.  
  1108.               <INITIAL,STRING,QUOTE>\.        { /* handle an escape ... */
  1109.                           ...
  1110.                           }
  1111.  
  1112.           will be active only when the current start condition is
  1113.           either "INITIAL", "STRING", or "QUOTE".
  1114.  
  1115.           Start conditions are declared in the definitions (first)
  1116.  
  1117.  
  1118.  
  1119.      Page 17                                         (printed 10/3/02)
  1120.  
  1121.  
  1122.  
  1123.  
  1124.  
  1125.  
  1126.      FFFFLLLLEEEEXXXX((((1111))))             VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))              FFFFLLLLEEEEXXXX((((1111))))
  1127.  
  1128.  
  1129.  
  1130.           section of the input using unindented lines beginning with
  1131.           either %%%%ssss or %%%%xxxx followed by a list of names.  The former
  1132.           declares _i_n_c_l_u_s_i_v_e start conditions, the latter _e_x_c_l_u_s_i_v_e
  1133.           start conditions.  A start condition is activated using the
  1134.           BBBBEEEEGGGGIIIINNNN action.  Until the next BBBBEEEEGGGGIIIINNNN action is executed,
  1135.           rules with the given start condition will be active and
  1136.           rules with other start conditions will be inactive.  If the
  1137.           start condition is _i_n_c_l_u_s_i_v_e, then rules with no start
  1138.           conditions at all will also be active.  If it is _e_x_c_l_u_s_i_v_e,
  1139.           then _o_n_l_y rules qualified with the start condition will be
  1140.           active.  A set of rules contingent on the same exclusive
  1141.           start condition describe a scanner which is independent of
  1142.           any of the other rules in the _f_l_e_x input.  Because of this,
  1143.           exclusive start conditions make it easy to specify "mini-
  1144.           scanners" which scan portions of the input that are
  1145.           syntactically different from the rest (e.g., comments).
  1146.  
  1147.           If the distinction between inclusive and exclusive start
  1148.           conditions is still a little vague, here's a simple example
  1149.           illustrating the connection between the two.  The set of
  1150.           rules:
  1151.  
  1152.               %s example
  1153.               %%
  1154.  
  1155.               <example>foo   do_something();
  1156.  
  1157.               bar            something_else();
  1158.  
  1159.           is equivalent to
  1160.  
  1161.               %x example
  1162.               %%
  1163.  
  1164.               <example>foo   do_something();
  1165.  
  1166.               <INITIAL,example>bar    something_else();
  1167.  
  1168.           Without the <<<<IIIINNNNIIIITTTTIIIIAAAALLLL,,,,eeeexxxxaaaammmmpppplllleeee>>>> qualifier, the _b_a_r pattern in
  1169.           the second example wouldn't be active (i.e., couldn't match)
  1170.           when in start condition eeeexxxxaaaammmmpppplllleeee.... If we just used <<<<eeeexxxxaaaammmmpppplllleeee>>>>
  1171.           to qualify _b_a_r, though, then it would only be active in
  1172.           eeeexxxxaaaammmmpppplllleeee and not in IIIINNNNIIIITTTTIIIIAAAALLLL,,,, while in the first example it's
  1173.           active in both, because in the first example the eeeexxxxaaaammmmpppplllleeee
  1174.           startion condition is an _i_n_c_l_u_s_i_v_e ((((%%%%ssss)))) start condition.
  1175.  
  1176.           Also note that the special start-condition specifier <<<<****>>>>
  1177.           matches every start condition.  Thus, the above example
  1178.           could also have been written;
  1179.  
  1180.               %x example
  1181.               %%
  1182.  
  1183.  
  1184.  
  1185.      Page 18                                         (printed 10/3/02)
  1186.  
  1187.  
  1188.  
  1189.  
  1190.  
  1191.  
  1192.      FFFFLLLLEEEEXXXX((((1111))))             VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))              FFFFLLLLEEEEXXXX((((1111))))
  1193.  
  1194.  
  1195.  
  1196.               <example>foo   do_something();
  1197.  
  1198.               <*>bar    something_else();
  1199.  
  1200.  
  1201.           The default rule (to EEEECCCCHHHHOOOO any unmatched character) remains
  1202.           active in start conditions.  It is equivalent to:
  1203.  
  1204.               <*>.|\n     ECHO;
  1205.  
  1206.  
  1207.           BBBBEEEEGGGGIIIINNNN((((0000)))) returns to the original state where only the rules
  1208.           with no start conditions are active.  This state can also be
  1209.           referred to as the start-condition "INITIAL", so
  1210.           BBBBEEEEGGGGIIIINNNN((((IIIINNNNIIIITTTTIIIIAAAALLLL)))) is equivalent to BBBBEEEEGGGGIIIINNNN((((0000)))).... (The parentheses
  1211.           around the start condition name are not required but are
  1212.           considered good style.)
  1213.  
  1214.           BBBBEEEEGGGGIIIINNNN actions can also be given as indented code at the
  1215.           beginning of the rules section.  For example, the following
  1216.           will cause the scanner to enter the "SPECIAL" start
  1217.           condition whenever yyyyyyyylllleeeexxxx(((()))) is called and the global variable
  1218.           _e_n_t_e_r__s_p_e_c_i_a_l is true:
  1219.  
  1220.                       int enter_special;
  1221.  
  1222.               %x SPECIAL
  1223.               %%
  1224.                       if ( enter_special )
  1225.                           BEGIN(SPECIAL);
  1226.  
  1227.               <SPECIAL>blahblahblah
  1228.               ...more rules follow...
  1229.  
  1230.  
  1231.           To illustrate the uses of start conditions, here is a
  1232.           scanner which provides two different interpretations of a
  1233.           string like "123.456".  By default it will treat it as three
  1234.           tokens, the integer "123", a dot ('.'), and the integer
  1235.           "456".  But if the string is preceded earlier in the line by
  1236.           the string "expect-floats" it will treat it as a single
  1237.           token, the floating-point number 123.456:
  1238.  
  1239.               %{
  1240.               #include <math.h>
  1241.               %}
  1242.               %s expect
  1243.  
  1244.               %%
  1245.               expect-floats        BEGIN(expect);
  1246.  
  1247.               <expect>[0-9]+"."[0-9]+      {
  1248.  
  1249.  
  1250.  
  1251.      Page 19                                         (printed 10/3/02)
  1252.  
  1253.  
  1254.  
  1255.  
  1256.  
  1257.  
  1258.      FFFFLLLLEEEEXXXX((((1111))))             VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))              FFFFLLLLEEEEXXXX((((1111))))
  1259.  
  1260.  
  1261.  
  1262.                           printf( "found a float, = %f\n",
  1263.                                   atof( yytext ) );
  1264.                           }
  1265.               <expect>\n           {
  1266.                           /* that's the end of the line, so
  1267.                            * we need another "expect-number"
  1268.                            * before we'll recognize any more
  1269.                            * numbers
  1270.                            */
  1271.                           BEGIN(INITIAL);
  1272.                           }
  1273.  
  1274.               [0-9]+      {
  1275.                           printf( "found an integer, = %d\n",
  1276.                                   atoi( yytext ) );
  1277.                           }
  1278.  
  1279.               "."         printf( "found a dot\n" );
  1280.  
  1281.           Here is a scanner which recognizes (and discards) C comments
  1282.           while maintaining a count of the current input line.
  1283.  
  1284.               %x comment
  1285.               %%
  1286.                       int line_num = 1;
  1287.  
  1288.               "/*"         BEGIN(comment);
  1289.  
  1290.               <comment>[^*\n]*        /* eat anything that's not a '*' */
  1291.               <comment>"*"+[^*/\n]*   /* eat up '*'s not followed by '/'s */
  1292.               <comment>\n             ++line_num;
  1293.               <comment>"*"+"/"        BEGIN(INITIAL);
  1294.  
  1295.           This scanner goes to a bit of trouble to match as much text
  1296.           as possible with each rule.  In general, when attempting to
  1297.           write a high-speed scanner try to match as much possible in
  1298.           each rule, as it's a big win.
  1299.  
  1300.           Note that start-conditions names are really integer values
  1301.           and can be stored as such.  Thus, the above could be
  1302.           extended in the following fashion:
  1303.  
  1304.               %x comment foo
  1305.               %%
  1306.                       int line_num = 1;
  1307.                       int comment_caller;
  1308.  
  1309.               "/*"         {
  1310.                            comment_caller = INITIAL;
  1311.                            BEGIN(comment);
  1312.                            }
  1313.  
  1314.  
  1315.  
  1316.  
  1317.      Page 20                                         (printed 10/3/02)
  1318.  
  1319.  
  1320.  
  1321.  
  1322.  
  1323.  
  1324.      FFFFLLLLEEEEXXXX((((1111))))             VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))              FFFFLLLLEEEEXXXX((((1111))))
  1325.  
  1326.  
  1327.  
  1328.               ...
  1329.  
  1330.               <foo>"/*"    {
  1331.                            comment_caller = foo;
  1332.                            BEGIN(comment);
  1333.                            }
  1334.  
  1335.               <comment>[^*\n]*        /* eat anything that's not a '*' */
  1336.               <comment>"*"+[^*/\n]*   /* eat up '*'s not followed by '/'s */
  1337.               <comment>\n             ++line_num;
  1338.               <comment>"*"+"/"        BEGIN(comment_caller);
  1339.  
  1340.           Furthermore, you can access the current start condition
  1341.           using the integer-valued YYYYYYYY____SSSSTTTTAAAARRRRTTTT macro.  For example, the
  1342.           above assignments to _c_o_m_m_e_n_t__c_a_l_l_e_r could instead be written
  1343.  
  1344.               comment_caller = YY_START;
  1345.  
  1346.           Flex provides YYYYYYYYSSSSTTTTAAAATTTTEEEE as an alias for YYYYYYYY____SSSSTTTTAAAARRRRTTTT (since that
  1347.           is what's used by AT&T _l_e_x).
  1348.  
  1349.           Note that start conditions do not have their own name-space;
  1350.           %s's and %x's declare names in the same fashion as
  1351.           #define's.
  1352.  
  1353.           Finally, here's an example of how to match C-style quoted
  1354.           strings using exclusive start conditions, including expanded
  1355.           escape sequences (but not including checking for a string
  1356.           that's too long):
  1357.  
  1358.               %x str
  1359.  
  1360.               %%
  1361.                       char string_buf[MAX_STR_CONST];
  1362.                       char *string_buf_ptr;
  1363.  
  1364.  
  1365.               \"      string_buf_ptr = string_buf; BEGIN(str);
  1366.  
  1367.               <str>\"        { /* saw closing quote - all done */
  1368.                       BEGIN(INITIAL);
  1369.                       *string_buf_ptr = '\0';
  1370.                       /* return string constant token type and
  1371.                        * value to parser
  1372.                        */
  1373.                       }
  1374.  
  1375.               <str>\n        {
  1376.                       /* error - unterminated string constant */
  1377.                       /* generate error message */
  1378.                       }
  1379.  
  1380.  
  1381.  
  1382.  
  1383.      Page 21                                         (printed 10/3/02)
  1384.  
  1385.  
  1386.  
  1387.  
  1388.  
  1389.  
  1390.      FFFFLLLLEEEEXXXX((((1111))))             VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))              FFFFLLLLEEEEXXXX((((1111))))
  1391.  
  1392.  
  1393.  
  1394.               <str>\\[0-7]{1,3} {
  1395.                       /* octal escape sequence */
  1396.                       int result;
  1397.  
  1398.                       (void) sscanf( yytext + 1, "%o", &result );
  1399.  
  1400.                       if ( result > 0xff )
  1401.                               /* error, constant is out-of-bounds */
  1402.  
  1403.                       *string_buf_ptr++ = result;
  1404.                       }
  1405.  
  1406.               <str>\\[0-9]+ {
  1407.                       /* generate error - bad escape sequence; something
  1408.                        * like '\48' or '\0777777'
  1409.                        */
  1410.                       }
  1411.  
  1412.               <str>\\n  *string_buf_ptr++ = '\n';
  1413.               <str>\\t  *string_buf_ptr++ = '\t';
  1414.               <str>\\r  *string_buf_ptr++ = '\r';
  1415.               <str>\\b  *string_buf_ptr++ = '\b';
  1416.               <str>\\f  *string_buf_ptr++ = '\f';
  1417.  
  1418.               <str>\\(.|\n)  *string_buf_ptr++ = yytext[1];
  1419.  
  1420.               <str>[^\\\n\"]+        {
  1421.                       char *yptr = yytext;
  1422.  
  1423.                       while ( *yptr )
  1424.                               *string_buf_ptr++ = *yptr++;
  1425.                       }
  1426.  
  1427.  
  1428.           Often, such as in some of the examples above, you wind up
  1429.           writing a whole bunch of rules all preceded by the same
  1430.           start condition(s).  Flex makes this a little easier and
  1431.           cleaner by introducing a notion of start condition _s_c_o_p_e. A
  1432.           start condition scope is begun with:
  1433.  
  1434.               <SCs>{
  1435.  
  1436.           where _S_C_s is a list of one or more start conditions.  Inside
  1437.           the start condition scope, every rule automatically has the
  1438.           prefix <_S_C_s> applied to it, until a '}' which matches the
  1439.           initial '{'. So, for example,
  1440.  
  1441.               <ESC>{
  1442.                   "\\n"   return '\n';
  1443.                   "\\r"   return '\r';
  1444.                   "\\f"   return '\f';
  1445.                   "\\0"   return '\0';
  1446.  
  1447.  
  1448.  
  1449.      Page 22                                         (printed 10/3/02)
  1450.  
  1451.  
  1452.  
  1453.  
  1454.  
  1455.  
  1456.      FFFFLLLLEEEEXXXX((((1111))))             VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))              FFFFLLLLEEEEXXXX((((1111))))
  1457.  
  1458.  
  1459.  
  1460.               }
  1461.  
  1462.           is equivalent to:
  1463.  
  1464.               <ESC>"\\n"  return '\n';
  1465.               <ESC>"\\r"  return '\r';
  1466.               <ESC>"\\f"  return '\f';
  1467.               <ESC>"\\0"  return '\0';
  1468.  
  1469.           Start condition scopes may be nested.
  1470.  
  1471.           Three routines are available for manipulating stacks of
  1472.           start conditions:
  1473.  
  1474.           vvvvooooiiiidddd yyyyyyyy____ppppuuuusssshhhh____ssssttttaaaatttteeee((((iiiinnnntttt nnnneeeewwww____ssssttttaaaatttteeee))))
  1475.                pushes the current start condition onto the top of the
  1476.                start condition stack and switches to _n_e_w__s_t_a_t_e as
  1477.                though you had used BBBBEEEEGGGGIIIINNNN nnnneeeewwww____ssssttttaaaatttteeee (recall that start
  1478.                condition names are also integers).
  1479.  
  1480.           vvvvooooiiiidddd yyyyyyyy____ppppoooopppp____ssssttttaaaatttteeee(((())))
  1481.                pops the top of the stack and switches to it via BBBBEEEEGGGGIIIINNNN....
  1482.  
  1483.           iiiinnnntttt yyyyyyyy____ttttoooopppp____ssssttttaaaatttteeee(((())))
  1484.                returns the top of the stack without altering the
  1485.                stack's contents.
  1486.  
  1487.           The start condition stack grows dynamically and so has no
  1488.           built-in size limitation.  If memory is exhausted, program
  1489.           execution aborts.
  1490.  
  1491.           To use start condition stacks, your scanner must include a
  1492.           %%%%ooooppppttttiiiioooonnnn ssssttttaaaacccckkkk directive (see Options below).
  1493.  
  1494.      MMMMUUUULLLLTTTTIIIIPPPPLLLLEEEE IIIINNNNPPPPUUUUTTTT BBBBUUUUFFFFFFFFEEEERRRRSSSS
  1495.           Some scanners (such as those which support "include" files)
  1496.           require reading from several input streams.  As _f_l_e_x
  1497.           scanners do a large amount of buffering, one cannot control
  1498.           where the next input will be read from by simply writing a
  1499.           YYYYYYYY____IIIINNNNPPPPUUUUTTTT which is sensitive to the scanning context.
  1500.           YYYYYYYY____IIIINNNNPPPPUUUUTTTT is only called when the scanner reaches the end of
  1501.           its buffer, which may be a long time after scanning a
  1502.           statement such as an "include" which requires switching the
  1503.           input source.
  1504.  
  1505.           To negotiate these sorts of problems, _f_l_e_x provides a
  1506.           mechanism for creating and switching between multiple input
  1507.           buffers.  An input buffer is created by using:
  1508.  
  1509.               YY_BUFFER_STATE yy_create_buffer( FILE *file, int size )
  1510.  
  1511.           which takes a _F_I_L_E pointer and a size and creates a buffer
  1512.  
  1513.  
  1514.  
  1515.      Page 23                                         (printed 10/3/02)
  1516.  
  1517.  
  1518.  
  1519.  
  1520.  
  1521.  
  1522.      FFFFLLLLEEEEXXXX((((1111))))             VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))              FFFFLLLLEEEEXXXX((((1111))))
  1523.  
  1524.  
  1525.  
  1526.           associated with the given file and large enough to hold _s_i_z_e
  1527.           characters (when in doubt, use YYYYYYYY____BBBBUUUUFFFF____SSSSIIIIZZZZEEEE for the size).
  1528.           It returns a YYYYYYYY____BBBBUUUUFFFFFFFFEEEERRRR____SSSSTTTTAAAATTTTEEEE handle, which may then be
  1529.           passed to other routines (see below).  The YYYYYYYY____BBBBUUUUFFFFFFFFEEEERRRR____SSSSTTTTAAAATTTTEEEE
  1530.           type is a pointer to an opaque ssssttttrrrruuuucccctttt yyyyyyyy____bbbbuuuuffffffffeeeerrrr____ssssttttaaaatttteeee
  1531.           structure, so you may safely initialize YY_BUFFER_STATE
  1532.           variables to ((((((((YYYYYYYY____BBBBUUUUFFFFFFFFEEEERRRR____SSSSTTTTAAAATTTTEEEE)))) 0000)))) if you wish, and also
  1533.           refer to the opaque structure in order to correctly declare
  1534.           input buffers in source files other than that of your
  1535.           scanner.  Note that the _F_I_L_E pointer in the call to
  1536.           yyyyyyyy____ccccrrrreeeeaaaatttteeee____bbbbuuuuffffffffeeeerrrr is only used as the value of _y_y_i_n seen by
  1537.           YYYYYYYY____IIIINNNNPPPPUUUUTTTT;;;; if you redefine YYYYYYYY____IIIINNNNPPPPUUUUTTTT so it no longer uses
  1538.           _y_y_i_n, then you can safely pass a nil _F_I_L_E pointer to
  1539.           yyyyyyyy____ccccrrrreeeeaaaatttteeee____bbbbuuuuffffffffeeeerrrr.... You select a particular buffer to scan
  1540.           from using:
  1541.  
  1542.               void yy_switch_to_buffer( YY_BUFFER_STATE new_buffer )
  1543.  
  1544.           switches the scanner's input buffer so subsequent tokens
  1545.           will come from _n_e_w__b_u_f_f_e_r. Note that yyyyyyyy____sssswwwwiiiittttcccchhhh____ttttoooo____bbbbuuuuffffffffeeeerrrr(((())))
  1546.           may be used by yywrap() to set things up for continued
  1547.           scanning, instead of opening a new file and pointing _y_y_i_n at
  1548.           it.  Note also that switching input sources via either
  1549.           yyyyyyyy____sssswwwwiiiittttcccchhhh____ttttoooo____bbbbuuuuffffffffeeeerrrr(((()))) or yyyyyyyywwwwrrrraaaapppp(((()))) does _n_o_t change the start
  1550.           condition.
  1551.  
  1552.               void yy_delete_buffer( YY_BUFFER_STATE buffer )
  1553.  
  1554.           is used to reclaim the storage associated with a buffer.  (
  1555.           bbbbuuuuffffffffeeeerrrr can be nil, in which case the routine does nothing.)
  1556.           You can also clear the current contents of a buffer using:
  1557.  
  1558.               void yy_flush_buffer( YY_BUFFER_STATE buffer )
  1559.  
  1560.           This function discards the buffer's contents, so the next
  1561.           time the scanner attempts to match a token from the buffer,
  1562.           it will first fill the buffer anew using YYYYYYYY____IIIINNNNPPPPUUUUTTTT....
  1563.  
  1564.           yyyyyyyy____nnnneeeewwww____bbbbuuuuffffffffeeeerrrr(((()))) is an alias for yyyyyyyy____ccccrrrreeeeaaaatttteeee____bbbbuuuuffffffffeeeerrrr(((()))),,,, provided
  1565.           for compatibility with the C++ use of _n_e_w and _d_e_l_e_t_e for
  1566.           creating and destroying dynamic objects.
  1567.  
  1568.           Finally, the YYYYYYYY____CCCCUUUURRRRRRRREEEENNNNTTTT____BBBBUUUUFFFFFFFFEEEERRRR macro returns a
  1569.           YYYYYYYY____BBBBUUUUFFFFFFFFEEEERRRR____SSSSTTTTAAAATTTTEEEE handle to the current buffer.
  1570.  
  1571.           Here is an example of using these features for writing a
  1572.           scanner which expands include files (the <<<<<<<<EEEEOOOOFFFF>>>>>>>> feature is
  1573.           discussed below):
  1574.  
  1575.               /* the "incl" state is used for picking up the name
  1576.                * of an include file
  1577.                */
  1578.  
  1579.  
  1580.  
  1581.      Page 24                                         (printed 10/3/02)
  1582.  
  1583.  
  1584.  
  1585.  
  1586.  
  1587.  
  1588.      FFFFLLLLEEEEXXXX((((1111))))             VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))              FFFFLLLLEEEEXXXX((((1111))))
  1589.  
  1590.  
  1591.  
  1592.               %x incl
  1593.  
  1594.               %{
  1595.               #define MAX_INCLUDE_DEPTH 10
  1596.               YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
  1597.               int include_stack_ptr = 0;
  1598.               %}
  1599.  
  1600.               %%
  1601.               include             BEGIN(incl);
  1602.  
  1603.               [a-z]+              ECHO;
  1604.               [^a-z\n]*\n?        ECHO;
  1605.  
  1606.               <incl>[ \t]*      /* eat the whitespace */
  1607.               <incl>[^ \t\n]+   { /* got the include file name */
  1608.                       if ( include_stack_ptr >= MAX_INCLUDE_DEPTH )
  1609.                           {
  1610.                           fprintf( stderr, "Includes nested too deeply" );
  1611.                           exit( 1 );
  1612.                           }
  1613.  
  1614.                       include_stack[include_stack_ptr++] =
  1615.                           YY_CURRENT_BUFFER;
  1616.  
  1617.                       yyin = fopen( yytext, "r" );
  1618.  
  1619.                       if ( ! yyin )
  1620.                           error( ... );
  1621.  
  1622.                       yy_switch_to_buffer(
  1623.                           yy_create_buffer( yyin, YY_BUF_SIZE ) );
  1624.  
  1625.                       BEGIN(INITIAL);
  1626.                       }
  1627.  
  1628.               <<EOF>> {
  1629.                       if ( --include_stack_ptr < 0 )
  1630.                           {
  1631.                           yyterminate();
  1632.                           }
  1633.  
  1634.                       else
  1635.                           {
  1636.                           yy_delete_buffer( YY_CURRENT_BUFFER );
  1637.                           yy_switch_to_buffer(
  1638.                                include_stack[include_stack_ptr] );
  1639.                           }
  1640.                       }
  1641.  
  1642.           Three routines are available for setting up input buffers
  1643.           for scanning in-memory strings instead of files.  All of
  1644.  
  1645.  
  1646.  
  1647.      Page 25                                         (printed 10/3/02)
  1648.  
  1649.  
  1650.  
  1651.  
  1652.  
  1653.  
  1654.      FFFFLLLLEEEEXXXX((((1111))))             VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))              FFFFLLLLEEEEXXXX((((1111))))
  1655.  
  1656.  
  1657.  
  1658.           them create a new input buffer for scanning the string, and
  1659.           return a corresponding YYYYYYYY____BBBBUUUUFFFFFFFFEEEERRRR____SSSSTTTTAAAATTTTEEEE handle (which you
  1660.           should delete with yyyyyyyy____ddddeeeelllleeeetttteeee____bbbbuuuuffffffffeeeerrrr(((()))) when done with it).
  1661.           They also switch to the new buffer using
  1662.           yyyyyyyy____sssswwwwiiiittttcccchhhh____ttttoooo____bbbbuuuuffffffffeeeerrrr(((()))),,,, so the next call to yyyyyyyylllleeeexxxx(((()))) will
  1663.           start scanning the string.
  1664.  
  1665.           yyyyyyyy____ssssccccaaaannnn____ssssttttrrrriiiinnnngggg((((ccccoooonnnnsssstttt cccchhhhaaaarrrr ****ssssttttrrrr))))
  1666.                scans a NUL-terminated string.
  1667.  
  1668.           yyyyyyyy____ssssccccaaaannnn____bbbbyyyytttteeeessss((((ccccoooonnnnsssstttt cccchhhhaaaarrrr ****bbbbyyyytttteeeessss,,,, iiiinnnntttt lllleeeennnn))))
  1669.                scans _l_e_n bytes (including possibly NUL's) starting at
  1670.                location _b_y_t_e_s.
  1671.  
  1672.           Note that both of these functions create and scan a _c_o_p_y of
  1673.           the string or bytes.  (This may be desirable, since yyyyyyyylllleeeexxxx(((())))
  1674.           modifies the contents of the buffer it is scanning.)  You
  1675.           can avoid the copy by using:
  1676.  
  1677.           yyyyyyyy____ssssccccaaaannnn____bbbbuuuuffffffffeeeerrrr((((cccchhhhaaaarrrr ****bbbbaaaasssseeee,,,, yyyyyyyy____ssssiiiizzzzeeee____tttt ssssiiiizzzzeeee))))
  1678.                which scans in place the buffer starting at _b_a_s_e,
  1679.                consisting of _s_i_z_e bytes, the last two bytes of which
  1680.                _m_u_s_t be YYYYYYYY____EEEENNNNDDDD____OOOOFFFF____BBBBUUUUFFFFFFFFEEEERRRR____CCCCHHHHAAAARRRR (ASCII NUL).  These last
  1681.                two bytes are not scanned; thus, scanning consists of
  1682.                bbbbaaaasssseeee[[[[0000]]]] through bbbbaaaasssseeee[[[[ssssiiiizzzzeeee----2222]]]],,,, inclusive.
  1683.  
  1684.                If you fail to set up _b_a_s_e in this manner (i.e., forget
  1685.                the final two YYYYYYYY____EEEENNNNDDDD____OOOOFFFF____BBBBUUUUFFFFFFFFEEEERRRR____CCCCHHHHAAAARRRR bytes), then
  1686.                yyyyyyyy____ssssccccaaaannnn____bbbbuuuuffffffffeeeerrrr(((()))) returns a nil pointer instead of
  1687.                creating a new input buffer.
  1688.  
  1689.                The type yyyyyyyy____ssssiiiizzzzeeee____tttt is an integral type to which you can
  1690.                cast an integer expression reflecting the size of the
  1691.                buffer.
  1692.  
  1693.      EEEENNNNDDDD----OOOOFFFF----FFFFIIIILLLLEEEE RRRRUUUULLLLEEEESSSS
  1694.           The special rule "<<EOF>>" indicates actions which are to be
  1695.           taken when an end-of-file is encountered and yywrap()
  1696.           returns non-zero (i.e., indicates no further files to
  1697.           process).  The action must finish by doing one of four
  1698.           things:
  1699.  
  1700.           -    assigning _y_y_i_n to a new input file (in previous
  1701.                versions of flex, after doing the assignment you had to
  1702.                call the special action YYYYYYYY____NNNNEEEEWWWW____FFFFIIIILLLLEEEE;;;; this is no longer
  1703.                necessary);
  1704.  
  1705.           -    executing a _r_e_t_u_r_n statement;
  1706.  
  1707.           -    executing the special yyyyyyyytttteeeerrrrmmmmiiiinnnnaaaatttteeee(((()))) action;
  1708.  
  1709.           -    or, switching to a new buffer using
  1710.  
  1711.  
  1712.  
  1713.      Page 26                                         (printed 10/3/02)
  1714.  
  1715.  
  1716.  
  1717.  
  1718.  
  1719.  
  1720.      FFFFLLLLEEEEXXXX((((1111))))             VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))              FFFFLLLLEEEEXXXX((((1111))))
  1721.  
  1722.  
  1723.  
  1724.                yyyyyyyy____sssswwwwiiiittttcccchhhh____ttttoooo____bbbbuuuuffffffffeeeerrrr(((()))) as shown in the example above.
  1725.  
  1726.           <<EOF>> rules may not be used with other patterns; they may
  1727.           only be qualified with a list of start conditions.  If an
  1728.           unqualified <<EOF>> rule is given, it applies to _a_l_l start
  1729.           conditions which do not already have <<EOF>> actions.  To
  1730.           specify an <<EOF>> rule for only the initial start
  1731.           condition, use
  1732.  
  1733.               <INITIAL><<EOF>>
  1734.  
  1735.  
  1736.           These rules are useful for catching things like unclosed
  1737.           comments.  An example:
  1738.  
  1739.               %x quote
  1740.               %%
  1741.  
  1742.               ...other rules for dealing with quotes...
  1743.  
  1744.               <quote><<EOF>>   {
  1745.                        error( "unterminated quote" );
  1746.                        yyterminate();
  1747.                        }
  1748.               <<EOF>>  {
  1749.                        if ( *++filelist )
  1750.                            yyin = fopen( *filelist, "r" );
  1751.                        else
  1752.                           yyterminate();
  1753.                        }
  1754.  
  1755.  
  1756.      MMMMIIIISSSSCCCCEEEELLLLLLLLAAAANNNNEEEEOOOOUUUUSSSS MMMMAAAACCCCRRRROOOOSSSS
  1757.           The macro YYYYYYYY____UUUUSSSSEEEERRRR____AAAACCCCTTTTIIIIOOOONNNN can be defined to provide an action
  1758.           which is always executed prior to the matched rule's action.
  1759.           For example, it could be #define'd to call a routine to
  1760.           convert yytext to lower-case.  When YYYYYYYY____UUUUSSSSEEEERRRR____AAAACCCCTTTTIIIIOOOONNNN is
  1761.           invoked, the variable _y_y__a_c_t gives the number of the matched
  1762.           rule (rules are numbered starting with 1).  Suppose you want
  1763.           to profile how often each of your rules is matched.  The
  1764.           following would do the trick:
  1765.  
  1766.               #define YY_USER_ACTION ++ctr[yy_act]
  1767.  
  1768.           where _c_t_r is an array to hold the counts for the different
  1769.           rules.  Note that the macro YYYYYYYY____NNNNUUUUMMMM____RRRRUUUULLLLEEEESSSS gives the total
  1770.           number of rules (including the default rule, even if you use
  1771.           ----ssss)))),,,, so a correct declaration for _c_t_r is:
  1772.  
  1773.               int ctr[YY_NUM_RULES];
  1774.  
  1775.  
  1776.  
  1777.  
  1778.  
  1779.      Page 27                                         (printed 10/3/02)
  1780.  
  1781.  
  1782.  
  1783.  
  1784.  
  1785.  
  1786.      FFFFLLLLEEEEXXXX((((1111))))             VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))              FFFFLLLLEEEEXXXX((((1111))))
  1787.  
  1788.  
  1789.  
  1790.           The macro YYYYYYYY____UUUUSSSSEEEERRRR____IIIINNNNIIIITTTT may be defined to provide an action
  1791.           which is always executed before the first scan (and before
  1792.           the scanner's internal initializations are done).  For
  1793.           example, it could be used to call a routine to read in a
  1794.           data table or open a logging file.
  1795.  
  1796.           The macro yyyyyyyy____sssseeeetttt____iiiinnnntttteeeerrrraaaaccccttttiiiivvvveeee((((iiiissss____iiiinnnntttteeeerrrraaaaccccttttiiiivvvveeee)))) can be used to
  1797.           control whether the current buffer is considered
  1798.           _i_n_t_e_r_a_c_t_i_v_e. An interactive buffer is processed more slowly,
  1799.           but must be used when the scanner's input source is indeed
  1800.           interactive to avoid problems due to waiting to fill buffers
  1801.           (see the discussion of the ----IIII flag below).  A non-zero value
  1802.           in the macro invocation marks the buffer as interactive, a
  1803.           zero value as non-interactive.  Note that use of this macro
  1804.           overrides %%%%ooooppppttttiiiioooonnnn aaaallllwwwwaaaayyyyssss----iiiinnnntttteeeerrrraaaaccccttttiiiivvvveeee or %%%%ooooppppttttiiiioooonnnn nnnneeeevvvveeeerrrr----
  1805.           iiiinnnntttteeeerrrraaaaccccttttiiiivvvveeee (see Options below).  yyyyyyyy____sssseeeetttt____iiiinnnntttteeeerrrraaaaccccttttiiiivvvveeee(((()))) must
  1806.           be invoked prior to beginning to scan the buffer that is (or
  1807.           is not) to be considered interactive.
  1808.  
  1809.           The macro yyyyyyyy____sssseeeetttt____bbbboooollll((((aaaatttt____bbbboooollll)))) can be used to control whether
  1810.           the current buffer's scanning context for the next token
  1811.           match is done as though at the beginning of a line.  A non-
  1812.           zero macro argument makes rules anchored with
  1813.  
  1814.           The macro YYYYYYYY____AAAATTTT____BBBBOOOOLLLL(((()))) returns true if the next token scanned
  1815.           from the current buffer will have '^' rules active, false
  1816.           otherwise.
  1817.  
  1818.           In the generated scanner, the actions are all gathered in
  1819.           one large switch statement and separated using YYYYYYYY____BBBBRRRREEEEAAAAKKKK,,,,
  1820.           which may be redefined.  By default, it is simply a "break",
  1821.           to separate each rule's action from the following rule's.
  1822.           Redefining YYYYYYYY____BBBBRRRREEEEAAAAKKKK allows, for example, C++ users to
  1823.           #define YY_BREAK to do nothing (while being very careful
  1824.           that every rule ends with a "break" or a "return"!) to avoid
  1825.           suffering from unreachable statement warnings where because
  1826.           a rule's action ends with "return", the YYYYYYYY____BBBBRRRREEEEAAAAKKKK is
  1827.           inaccessible.
  1828.  
  1829.      VVVVAAAALLLLUUUUEEEESSSS AAAAVVVVAAAAIIIILLLLAAAABBBBLLLLEEEE TTTTOOOO TTTTHHHHEEEE UUUUSSSSEEEERRRR
  1830.           This section summarizes the various values available to the
  1831.           user in the rule actions.
  1832.  
  1833.           -    cccchhhhaaaarrrr ****yyyyyyyytttteeeexxxxtttt holds the text of the current token.  It
  1834.                may be modified but not lengthened (you cannot append
  1835.                characters to the end).
  1836.  
  1837.                If the special directive %%%%aaaarrrrrrrraaaayyyy appears in the first
  1838.                section of the scanner description, then yyyyyyyytttteeeexxxxtttt is
  1839.                instead declared cccchhhhaaaarrrr yyyyyyyytttteeeexxxxtttt[[[[YYYYYYYYLLLLMMMMAAAAXXXX]]]],,,, where YYYYYYYYLLLLMMMMAAAAXXXX is a
  1840.                macro definition that you can redefine in the first
  1841.                section if you don't like the default value (generally
  1842.  
  1843.  
  1844.  
  1845.      Page 28                                         (printed 10/3/02)
  1846.  
  1847.  
  1848.  
  1849.  
  1850.  
  1851.  
  1852.      FFFFLLLLEEEEXXXX((((1111))))             VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))              FFFFLLLLEEEEXXXX((((1111))))
  1853.  
  1854.  
  1855.  
  1856.                8KB).  Using %%%%aaaarrrrrrrraaaayyyy results in somewhat slower
  1857.                scanners, but the value of yyyyyyyytttteeeexxxxtttt becomes immune to
  1858.                calls to _i_n_p_u_t() and _u_n_p_u_t(), which potentially destroy
  1859.                its value when yyyyyyyytttteeeexxxxtttt is a character pointer.  The
  1860.                opposite of %%%%aaaarrrrrrrraaaayyyy is %%%%ppppooooiiiinnnntttteeeerrrr,,,, which is the default.
  1861.  
  1862.                You cannot use %%%%aaaarrrrrrrraaaayyyy when generating C++ scanner
  1863.                classes (the ----++++ flag).
  1864.  
  1865.           -    iiiinnnntttt yyyyyyyylllleeeennnngggg holds the length of the current token.
  1866.  
  1867.           -    FFFFIIIILLLLEEEE ****yyyyyyyyiiiinnnn is the file which by default _f_l_e_x reads
  1868.                from.  It may be redefined but doing so only makes
  1869.                sense before scanning begins or after an EOF has been
  1870.                encountered.  Changing it in the midst of scanning will
  1871.                have unexpected results since _f_l_e_x buffers its input;
  1872.                use yyyyyyyyrrrreeeessssttttaaaarrrrtttt(((()))) instead.  Once scanning terminates
  1873.                because an end-of-file has been seen, you can assign
  1874.                _y_y_i_n at the new input file and then call the scanner
  1875.                again to continue scanning.
  1876.  
  1877.           -    vvvvooooiiiidddd yyyyyyyyrrrreeeessssttttaaaarrrrtttt(((( FFFFIIIILLLLEEEE ****nnnneeeewwww____ffffiiiilllleeee )))) may be called to point
  1878.                _y_y_i_n at the new input file.  The switch-over to the new
  1879.                file is immediate (any previously buffered-up input is
  1880.                lost).  Note that calling yyyyyyyyrrrreeeessssttttaaaarrrrtttt(((()))) with _y_y_i_n as an
  1881.                argument thus throws away the current input buffer and
  1882.                continues scanning the same input file.
  1883.  
  1884.           -    FFFFIIIILLLLEEEE ****yyyyyyyyoooouuuutttt is the file to which EEEECCCCHHHHOOOO actions are done.
  1885.                It can be reassigned by the user.
  1886.  
  1887.           -    YYYYYYYY____CCCCUUUURRRRRRRREEEENNNNTTTT____BBBBUUUUFFFFFFFFEEEERRRR returns a YYYYYYYY____BBBBUUUUFFFFFFFFEEEERRRR____SSSSTTTTAAAATTTTEEEE handle to
  1888.                the current buffer.
  1889.  
  1890.           -    YYYYYYYY____SSSSTTTTAAAARRRRTTTT returns an integer value corresponding to the
  1891.                current start condition.  You can subsequently use this
  1892.                value with BBBBEEEEGGGGIIIINNNN to return to that start condition.
  1893.  
  1894.      IIIINNNNTTTTEEEERRRRFFFFAAAACCCCIIIINNNNGGGG WWWWIIIITTTTHHHH YYYYAAAACCCCCCCC
  1895.           One of the main uses of _f_l_e_x is as a companion to the _y_a_c_c
  1896.           parser-generator.  _y_a_c_c parsers expect to call a routine
  1897.           named yyyyyyyylllleeeexxxx(((()))) to find the next input token.  The routine is
  1898.           supposed to return the type of the next token as well as
  1899.           putting any associated value in the global yyyyyyyyllllvvvvaaaallll.... To use
  1900.           _f_l_e_x with _y_a_c_c, one specifies the ----dddd option to _y_a_c_c to
  1901.           instruct it to generate the file yyyy....ttttaaaabbbb....hhhh containing
  1902.           definitions of all the %%%%ttttooookkkkeeeennnnssss appearing in the _y_a_c_c input.
  1903.           This file is then included in the _f_l_e_x scanner.  For
  1904.           example, if one of the tokens is "TOK_NUMBER", part of the
  1905.           scanner might look like:
  1906.  
  1907.               %{
  1908.  
  1909.  
  1910.  
  1911.      Page 29                                         (printed 10/3/02)
  1912.  
  1913.  
  1914.  
  1915.  
  1916.  
  1917.  
  1918.      FFFFLLLLEEEEXXXX((((1111))))             VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))              FFFFLLLLEEEEXXXX((((1111))))
  1919.  
  1920.  
  1921.  
  1922.               #include "y.tab.h"
  1923.               %}
  1924.  
  1925.               %%
  1926.  
  1927.               [0-9]+        yylval = atoi( yytext ); return TOK_NUMBER;
  1928.  
  1929.  
  1930.      OOOOPPPPTTTTIIIIOOOONNNNSSSS
  1931.           _f_l_e_x has the following options:
  1932.  
  1933.           ----bbbb   Generate backing-up information to _l_e_x._b_a_c_k_u_p. This is
  1934.                a list of scanner states which require backing up and
  1935.                the input characters on which they do so.  By adding
  1936.                rules one can remove backing-up states.  If _a_l_l
  1937.                backing-up states are eliminated and ----CCCCffff or ----CCCCFFFF is
  1938.                used, the generated scanner will run faster (see the ----pppp
  1939.                flag).  Only users who wish to squeeze every last cycle
  1940.                out of their scanners need worry about this option.
  1941.                (See the section on Performance Considerations below.)
  1942.  
  1943.           ----cccc   is a do-nothing, deprecated option included for POSIX
  1944.                compliance.
  1945.  
  1946.           ----dddd   makes the generated scanner run in _d_e_b_u_g mode.
  1947.                Whenever a pattern is recognized and the global
  1948.                yyyyyyyy____fffflllleeeexxxx____ddddeeeebbbbuuuugggg is non-zero (which is the default), the
  1949.                scanner will write to _s_t_d_e_r_r a line of the form:
  1950.  
  1951.                    --accepting rule at line 53 ("the matched text")
  1952.  
  1953.                The line number refers to the location of the rule in
  1954.                the file defining the scanner (i.e., the file that was
  1955.                fed to flex).  Messages are also generated when the
  1956.                scanner backs up, accepts the default rule, reaches the
  1957.                end of its input buffer (or encounters a NUL; at this
  1958.                point, the two look the same as far as the scanner's
  1959.                concerned), or reaches an end-of-file.
  1960.  
  1961.           ----ffff   specifies _f_a_s_t _s_c_a_n_n_e_r. No table compression is done
  1962.                and stdio is bypassed.  The result is large but fast.
  1963.                This option is equivalent to ----CCCCffffrrrr (see below).
  1964.  
  1965.           ----hhhh   generates a "help" summary of _f_l_e_x'_s options to _s_t_d_o_u_t
  1966.                and then exits.  ----???? and --------hhhheeeellllpppp are synonyms for ----hhhh....
  1967.  
  1968.           ----iiii   instructs _f_l_e_x to generate a _c_a_s_e-_i_n_s_e_n_s_i_t_i_v_e scanner.
  1969.                The case of letters given in the _f_l_e_x input patterns
  1970.                will be ignored, and tokens in the input will be
  1971.                matched regardless of case.  The matched text given in
  1972.                _y_y_t_e_x_t will have the preserved case (i.e., it will not
  1973.                be folded).
  1974.  
  1975.  
  1976.  
  1977.      Page 30                                         (printed 10/3/02)
  1978.  
  1979.  
  1980.  
  1981.  
  1982.  
  1983.  
  1984.      FFFFLLLLEEEEXXXX((((1111))))             VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))              FFFFLLLLEEEEXXXX((((1111))))
  1985.  
  1986.  
  1987.  
  1988.           ----llll   turns on maximum compatibility with the original AT&T
  1989.                _l_e_x implementation.  Note that this does not mean _f_u_l_l
  1990.                compatibility.  Use of this option costs a considerable
  1991.                amount of performance, and it cannot be used with the
  1992.                ----++++,,,, ----ffff,,,, ----FFFF,,,, ----CCCCffff,,,, or ----CCCCFFFF options.  For details on the
  1993.                compatibilities it provides, see the section
  1994.                "Incompatibilities With Lex And POSIX" below.  This
  1995.                option also results in the name YYYYYYYY____FFFFLLLLEEEEXXXX____LLLLEEEEXXXX____CCCCOOOOMMMMPPPPAAAATTTT
  1996.                being #define'd in the generated scanner.
  1997.  
  1998.           ----nnnn   is another do-nothing, deprecated option included only
  1999.                for POSIX compliance.
  2000.  
  2001.           ----pppp   generates a performance report to stderr.  The report
  2002.                consists of comments regarding features of the _f_l_e_x
  2003.                input file which will cause a serious loss of
  2004.                performance in the resulting scanner.  If you give the
  2005.                flag twice, you will also get comments regarding
  2006.                features that lead to minor performance losses.
  2007.  
  2008.                Note that the use of RRRREEEEJJJJEEEECCCCTTTT,,,, %%%%ooooppppttttiiiioooonnnn yyyyyyyylllliiiinnnneeeennnnoooo,,,, and
  2009.                variable trailing context (see the Deficiencies / Bugs
  2010.                section below) entails a substantial performance
  2011.                penalty; use of _y_y_m_o_r_e(), the ^^^^ operator, and the ----IIII
  2012.                flag entail minor performance penalties.
  2013.  
  2014.           ----ssss   causes the _d_e_f_a_u_l_t _r_u_l_e (that unmatched scanner input
  2015.                is echoed to _s_t_d_o_u_t) to be suppressed.  If the scanner
  2016.                encounters input that does not match any of its rules,
  2017.                it aborts with an error.  This option is useful for
  2018.                finding holes in a scanner's rule set.
  2019.  
  2020.           ----tttt   instructs _f_l_e_x to write the scanner it generates to
  2021.                standard output instead of lllleeeexxxx....yyyyyyyy....cccc....
  2022.  
  2023.           ----vvvv   specifies that _f_l_e_x should write to _s_t_d_e_r_r a summary of
  2024.                statistics regarding the scanner it generates.  Most of
  2025.                the statistics are meaningless to the casual _f_l_e_x user,
  2026.                but the first line identifies the version of _f_l_e_x (same
  2027.                as reported by ----VVVV)))),,,, and the next line the flags used
  2028.                when generating the scanner, including those that are
  2029.                on by default.
  2030.  
  2031.           ----wwww   suppresses warning messages.
  2032.  
  2033.           ----BBBB   instructs _f_l_e_x to generate a _b_a_t_c_h scanner, the
  2034.                opposite of _i_n_t_e_r_a_c_t_i_v_e scanners generated by ----IIII (see
  2035.                below).  In general, you use ----BBBB when you are _c_e_r_t_a_i_n
  2036.                that your scanner will never be used interactively, and
  2037.                you want to squeeze a _l_i_t_t_l_e more performance out of
  2038.                it.  If your goal is instead to squeeze out a _l_o_t more
  2039.                performance, you should  be using the ----CCCCffff or ----CCCCFFFF
  2040.  
  2041.  
  2042.  
  2043.      Page 31                                         (printed 10/3/02)
  2044.  
  2045.  
  2046.  
  2047.  
  2048.  
  2049.  
  2050.      FFFFLLLLEEEEXXXX((((1111))))             VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))              FFFFLLLLEEEEXXXX((((1111))))
  2051.  
  2052.  
  2053.  
  2054.                options (discussed below), which turn on ----BBBB
  2055.                automatically anyway.
  2056.  
  2057.           ----FFFF   specifies that the _f_a_s_t scanner table representation
  2058.                should be used (and stdio bypassed).  This
  2059.                representation is about as fast as the full table
  2060.                representation ((((----ffff)))),,,, and for some sets of patterns will
  2061.                be considerably smaller (and for others, larger).  In
  2062.                general, if the pattern set contains both "keywords"
  2063.                and a catch-all, "identifier" rule, such as in the set:
  2064.  
  2065.                    "case"    return TOK_CASE;
  2066.                    "switch"  return TOK_SWITCH;
  2067.                    ...
  2068.                    "default" return TOK_DEFAULT;
  2069.                    [a-z]+    return TOK_ID;
  2070.  
  2071.                then you're better off using the full table
  2072.                representation.  If only the "identifier" rule is
  2073.                present and you then use a hash table or some such to
  2074.                detect the keywords, you're better off using ----FFFF....
  2075.  
  2076.                This option is equivalent to ----CCCCFFFFrrrr (see below).  It
  2077.                cannot be used with ----++++....
  2078.  
  2079.           ----IIII   instructs _f_l_e_x to generate an _i_n_t_e_r_a_c_t_i_v_e scanner.  An
  2080.                interactive scanner is one that only looks ahead to
  2081.                decide what token has been matched if it absolutely
  2082.                must.  It turns out that always looking one extra
  2083.                character ahead, even if the scanner has already seen
  2084.                enough text to disambiguate the current token, is a bit
  2085.                faster than only looking ahead when necessary.  But
  2086.                scanners that always look ahead give dreadful
  2087.                interactive performance; for example, when a user types
  2088.                a newline, it is not recognized as a newline token
  2089.                until they enter _a_n_o_t_h_e_r token, which often means
  2090.                typing in another whole line.
  2091.  
  2092.                _F_l_e_x scanners default to _i_n_t_e_r_a_c_t_i_v_e unless you use the
  2093.                ----CCCCffff or ----CCCCFFFF table-compression options (see below).
  2094.                That's because if you're looking for high-performance
  2095.                you should be using one of these options, so if you
  2096.                didn't, _f_l_e_x assumes you'd rather trade off a bit of
  2097.                run-time performance for intuitive interactive
  2098.                behavior.  Note also that you _c_a_n_n_o_t use ----IIII in
  2099.                conjunction with ----CCCCffff or ----CCCCFFFF.... Thus, this option is not
  2100.                really needed; it is on by default for all those cases
  2101.                in which it is allowed.
  2102.  
  2103.                You can force a scanner to _n_o_t be interactive by using
  2104.                ----BBBB (see above).
  2105.  
  2106.  
  2107.  
  2108.  
  2109.      Page 32                                         (printed 10/3/02)
  2110.  
  2111.  
  2112.  
  2113.  
  2114.  
  2115.  
  2116.      FFFFLLLLEEEEXXXX((((1111))))             VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))              FFFFLLLLEEEEXXXX((((1111))))
  2117.  
  2118.  
  2119.  
  2120.           ----LLLL   instructs _f_l_e_x not to generate ####lllliiiinnnneeee directives.
  2121.                Without this option, _f_l_e_x peppers the generated scanner
  2122.                with #line directives so error messages in the actions
  2123.                will be correctly located with respect to either the
  2124.                original _f_l_e_x input file (if the errors are due to code
  2125.                in the input file), or lllleeeexxxx....yyyyyyyy....cccc (if the errors are
  2126.                _f_l_e_x'_s fault -- you should report these sorts of errors
  2127.                to the email address given below).
  2128.  
  2129.           ----TTTT   makes _f_l_e_x run in _t_r_a_c_e mode.  It will generate a lot
  2130.                of messages to _s_t_d_e_r_r concerning the form of the input
  2131.                and the resultant non-deterministic and deterministic
  2132.                finite automata.  This option is mostly for use in
  2133.                maintaining _f_l_e_x.
  2134.  
  2135.           ----VVVV   prints the version number to _s_t_d_o_u_t and exits.
  2136.                --------vvvveeeerrrrssssiiiioooonnnn is a synonym for ----VVVV....
  2137.  
  2138.           --------ppppoooossssiiiixxxx----ccccoooommmmppppaaaatttt
  2139.                turns on maximum compatibility with the POSIX 1003.2-
  2140.                1992 definition of _l_e_x (----XXXX is a synonym for
  2141.                --------ppppoooossssiiiixxxx----ccccoooommmmppppaaaatttt).  Since _f_l_e_x was originally designed to
  2142.                implement the POSIX definition of _l_e_x this generally
  2143.                involves very few changes in behavior.  At the current
  2144.                writing the known differences between _f_l_e_x and the
  2145.                POSIX standard are:
  2146.  
  2147.                +    In POSIX and AT&T _l_e_x, the repeat operator, {{{{}}}},
  2148.                     has lower precedence than concatenation (thus
  2149.                     aaaabbbb{{{{3333}}}} yields aaaabbbbaaaabbbbaaaabbbb).  Most POSIX utilities use an
  2150.                     Extended Regular Expression (ERE) precedence that
  2151.                     has the precedence of the repeat operator higher
  2152.                     than concatenation (which causes aaaabbbb{{{{3333}}}} to yield
  2153.                     aaaabbbbbbbbbbbb).  By default, _f_l_e_x places the precedence of
  2154.                     the repeat operator higher than concatenation
  2155.                     which matches the ERE processing of other POSIX
  2156.                     utilities.  When either --------ppppoooossssiiiixxxx----ccccoooommmmppppaaaatttt or ----llll are
  2157.                     specified, _f_l_e_x will use the traditional AT&T and
  2158.                     POSIX-compliant precedence for the repeat operator
  2159.                     where concatenation has higher precedence than the
  2160.                     repeat operator.
  2161.  
  2162.           ----7777   instructs _f_l_e_x to generate a 7-bit scanner, i.e., one
  2163.                which can only recognized 7-bit characters in its
  2164.                input.  The advantage of using ----7777 is that the scanner's
  2165.                tables can be up to half the size of those generated
  2166.                using the ----8888 option (see below).  The disadvantage is
  2167.                that such scanners often hang or crash if their input
  2168.                contains an 8-bit character.
  2169.  
  2170.                Note, however, that unless you generate your scanner
  2171.                using the ----CCCCffff or ----CCCCFFFF table compression options, use of
  2172.  
  2173.  
  2174.  
  2175.      Page 33                                         (printed 10/3/02)
  2176.  
  2177.  
  2178.  
  2179.  
  2180.  
  2181.  
  2182.      FFFFLLLLEEEEXXXX((((1111))))             VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))              FFFFLLLLEEEEXXXX((((1111))))
  2183.  
  2184.  
  2185.  
  2186.                ----7777 will save only a small amount of table space, and
  2187.                make your scanner considerably less portable.  _F_l_e_x'_s
  2188.                default behavior is to generate an 8-bit scanner unless
  2189.                you use the ----CCCCffff or ----CCCCFFFF,,,, in which case _f_l_e_x defaults to
  2190.                generating 7-bit scanners unless your site was always
  2191.                configured to generate 8-bit scanners (as will often be
  2192.                the case with non-USA sites).  You can tell whether
  2193.                flex generated a 7-bit or an 8-bit scanner by
  2194.                inspecting the flag summary in the ----vvvv output as
  2195.                described above.
  2196.  
  2197.                Note that if you use ----CCCCffffeeee or ----CCCCFFFFeeee (those table
  2198.                compression options, but also using equivalence classes
  2199.                as discussed see below), flex still defaults to
  2200.                generating an 8-bit scanner, since usually with these
  2201.                compression options full 8-bit tables are not much more
  2202.                expensive than 7-bit tables.
  2203.  
  2204.           ----8888   instructs _f_l_e_x to generate an 8-bit scanner, i.e., one
  2205.                which can recognize 8-bit characters.  This flag is
  2206.                only needed for scanners generated using ----CCCCffff or ----CCCCFFFF,,,, as
  2207.                otherwise flex defaults to generating an 8-bit scanner
  2208.                anyway.
  2209.  
  2210.                See the discussion of ----7777 above for flex's default
  2211.                behavior and the tradeoffs between 7-bit and 8-bit
  2212.                scanners.
  2213.  
  2214.           ----++++   specifies that you want flex to generate a C++ scanner
  2215.                class.  See the section on Generating C++ Scanners
  2216.                below for details.
  2217.  
  2218.           ----CCCC[[[[aaaaeeeeffffFFFFmmmmrrrr]]]]
  2219.                controls the degree of table compression and, more
  2220.                generally, trade-offs between small scanners and fast
  2221.                scanners.
  2222.  
  2223.                ----CCCCaaaa ("align") instructs flex to trade off larger tables
  2224.                in the generated scanner for faster performance because
  2225.                the elements of the tables are better aligned for
  2226.                memory access and computation.  On some RISC
  2227.                architectures, fetching and manipulating longwords is
  2228.                more efficient than with smaller-sized units such as
  2229.                shortwords.  This option can double the size of the
  2230.                tables used by your scanner.
  2231.  
  2232.                ----CCCCeeee directs _f_l_e_x to construct _e_q_u_i_v_a_l_e_n_c_e _c_l_a_s_s_e_s,
  2233.                i.e., sets of characters which have identical lexical
  2234.                properties (for example, if the only appearance of
  2235.                digits in the _f_l_e_x input is in the character class
  2236.                "[0-9]" then the digits '0', '1', ..., '9' will all be
  2237.                put in the same equivalence class).  Equivalence
  2238.  
  2239.  
  2240.  
  2241.      Page 34                                         (printed 10/3/02)
  2242.  
  2243.  
  2244.  
  2245.  
  2246.  
  2247.  
  2248.      FFFFLLLLEEEEXXXX((((1111))))             VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))              FFFFLLLLEEEEXXXX((((1111))))
  2249.  
  2250.  
  2251.  
  2252.                classes usually give dramatic reductions in the final
  2253.                table/object file sizes (typically a factor of 2-5) and
  2254.                are pretty cheap performance-wise (one array look-up
  2255.                per character scanned).
  2256.  
  2257.                ----CCCCffff specifies that the _f_u_l_l scanner tables should be
  2258.                generated - _f_l_e_x should not compress the tables by
  2259.                taking advantages of similar transition functions for
  2260.                different states.
  2261.  
  2262.                ----CCCCFFFF specifies that the alternate fast scanner
  2263.                representation (described above under the ----FFFF flag)
  2264.                should be used.  This option cannot be used with ----++++....
  2265.  
  2266.                ----CCCCmmmm directs _f_l_e_x to construct _m_e_t_a-_e_q_u_i_v_a_l_e_n_c_e _c_l_a_s_s_e_s,
  2267.                which are sets of equivalence classes (or characters,
  2268.                if equivalence classes are not being used) that are
  2269.                commonly used together.  Meta-equivalence classes are
  2270.                often a big win when using compressed tables, but they
  2271.                have a moderate performance impact (one or two "if"
  2272.                tests and one array look-up per character scanned).
  2273.  
  2274.                ----CCCCrrrr causes the generated scanner to _b_y_p_a_s_s use of the
  2275.                standard I/O library (stdio) for input.  Instead of
  2276.                calling ffffrrrreeeeaaaadddd(((()))) or ggggeeeettttcccc(((()))),,,, the scanner will use the
  2277.                rrrreeeeaaaadddd(((()))) system call, resulting in a performance gain
  2278.                which varies from system to system, but in general is
  2279.                probably negligible unless you are also using ----CCCCffff or
  2280.                ----CCCCFFFF.... Using ----CCCCrrrr can cause strange behavior if, for
  2281.                example, you read from _y_y_i_n using stdio prior to
  2282.                calling the scanner (because the scanner will miss
  2283.                whatever text your previous reads left in the stdio
  2284.                input buffer).
  2285.  
  2286.                ----CCCCrrrr has no effect if you define YYYYYYYY____IIIINNNNPPPPUUUUTTTT (see The
  2287.                Generated Scanner above).
  2288.  
  2289.                A lone ----CCCC specifies that the scanner tables should be
  2290.                compressed but neither equivalence classes nor meta-
  2291.                equivalence classes should be used.
  2292.  
  2293.                The options ----CCCCffff or ----CCCCFFFF and ----CCCCmmmm do not make sense
  2294.                together - there is no opportunity for meta-equivalence
  2295.                classes if the table is not being compressed.
  2296.                Otherwise the options may be freely mixed, and are
  2297.                cumulative.
  2298.  
  2299.                The default setting is ----CCCCeeeemmmm,,,, which specifies that _f_l_e_x
  2300.                should generate equivalence classes and meta-
  2301.                equivalence classes.  This setting provides the highest
  2302.                degree of table compression.  You can trade off
  2303.                faster-executing scanners at the cost of larger tables
  2304.  
  2305.  
  2306.  
  2307.      Page 35                                         (printed 10/3/02)
  2308.  
  2309.  
  2310.  
  2311.  
  2312.  
  2313.  
  2314.      FFFFLLLLEEEEXXXX((((1111))))             VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))              FFFFLLLLEEEEXXXX((((1111))))
  2315.  
  2316.  
  2317.  
  2318.                with the following generally being true:
  2319.  
  2320.                    slowest & smallest
  2321.                          -Cem
  2322.                          -Cm
  2323.                          -Ce
  2324.                          -C
  2325.                          -C{f,F}e
  2326.                          -C{f,F}
  2327.                          -C{f,F}a
  2328.                    fastest & largest
  2329.  
  2330.                Note that scanners with the smallest tables are usually
  2331.                generated and compiled the quickest, so during
  2332.                development you will usually want to use the default,
  2333.                maximal compression.
  2334.  
  2335.                ----CCCCffffeeee is often a good compromise between speed and size
  2336.                for production scanners.
  2337.  
  2338.           ----oooooooouuuuttttppppuuuutttt
  2339.                directs flex to write the scanner to the file oooouuuuttttppppuuuutttt
  2340.                instead of lllleeeexxxx....yyyyyyyy....cccc.... If you combine ----oooo with the ----tttt
  2341.                option, then the scanner is written to _s_t_d_o_u_t but its
  2342.                ####lllliiiinnnneeee directives (see the ----LLLL option above) refer to the
  2343.                file oooouuuuttttppppuuuutttt....
  2344.  
  2345.           ----PPPPpppprrrreeeeffffiiiixxxx
  2346.                changes the default _y_y prefix used by _f_l_e_x for all
  2347.                globally-visible variable and function names to instead
  2348.                be _p_r_e_f_i_x. For example, ----PPPPffffoooooooo changes the name of
  2349.                yyyyyyyytttteeeexxxxtttt to ffffooooooootttteeeexxxxtttt.... It also changes the name of the
  2350.                default output file from lllleeeexxxx....yyyyyyyy....cccc to lllleeeexxxx....ffffoooooooo....cccc.... Here
  2351.                are all of the names affected:
  2352.  
  2353.                    yy_create_buffer
  2354.                    yy_delete_buffer
  2355.                    yy_flex_debug
  2356.                    yy_init_buffer
  2357.                    yy_flush_buffer
  2358.                    yy_load_buffer_state
  2359.                    yy_switch_to_buffer
  2360.                    yyin
  2361.                    yyleng
  2362.                    yylex
  2363.                    yylineno
  2364.                    yyout
  2365.                    yyrestart
  2366.                    yytext
  2367.                    yywrap
  2368.  
  2369.                (If you are using a C++ scanner, then only yyyyyyyywwwwrrrraaaapppp and
  2370.  
  2371.  
  2372.  
  2373.      Page 36                                         (printed 10/3/02)
  2374.  
  2375.  
  2376.  
  2377.  
  2378.  
  2379.  
  2380.      FFFFLLLLEEEEXXXX((((1111))))             VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))              FFFFLLLLEEEEXXXX((((1111))))
  2381.  
  2382.  
  2383.  
  2384.                yyyyyyyyFFFFlllleeeexxxxLLLLeeeexxxxeeeerrrr are affected.)  Within your scanner itself,
  2385.                you can still refer to the global variables and
  2386.                functions using either version of their name; but
  2387.                externally, they have the modified name.
  2388.  
  2389.                This option lets you easily link together multiple _f_l_e_x
  2390.                programs into the same executable.  Note, though, that
  2391.                using this option also renames yyyyyyyywwwwrrrraaaapppp(((()))),,,, so you now
  2392.                _m_u_s_t either provide your own (appropriately-named)
  2393.                version of the routine for your scanner, or use %%%%ooooppppttttiiiioooonnnn
  2394.                nnnnooooyyyyyyyywwwwrrrraaaapppp,,,, as linking with ----llllffffllll no longer provides one
  2395.                for you by default.
  2396.  
  2397.           ----SSSSsssskkkkeeeelllleeeettttoooonnnn____ffffiiiilllleeee
  2398.                overrides the default skeleton file from which _f_l_e_x
  2399.                constructs its scanners.  You'll never need this option
  2400.                unless you are doing _f_l_e_x maintenance or development.
  2401.  
  2402.           _f_l_e_x also provides a mechanism for controlling options
  2403.           within the scanner specification itself, rather than from
  2404.           the flex command-line.  This is done by including %%%%ooooppppttttiiiioooonnnn
  2405.           directives in the first section of the scanner
  2406.           specification.  You can specify multiple options with a
  2407.           single %%%%ooooppppttttiiiioooonnnn directive, and multiple directives in the
  2408.           first section of your flex input file.
  2409.  
  2410.           Most options are given simply as names, optionally preceded
  2411.           by the word "no" (with no intervening whitespace) to negate
  2412.           their meaning.  A number are equivalent to flex flags or
  2413.           their negation:
  2414.  
  2415.               7bit            -7 option
  2416.               8bit            -8 option
  2417.               align           -Ca option
  2418.               backup          -b option
  2419.               batch           -B option
  2420.               c++             -+ option
  2421.  
  2422.               caseful or
  2423.               case-sensitive  opposite of -i (default)
  2424.  
  2425.               case-insensitive or
  2426.               caseless        -i option
  2427.  
  2428.               debug           -d option
  2429.               default         opposite of -s option
  2430.               ecs             -Ce option
  2431.               fast            -F option
  2432.               full            -f option
  2433.               interactive     -I option
  2434.               lex-compat      -l option
  2435.               meta-ecs        -Cm option
  2436.  
  2437.  
  2438.  
  2439.      Page 37                                         (printed 10/3/02)
  2440.  
  2441.  
  2442.  
  2443.  
  2444.  
  2445.  
  2446.      FFFFLLLLEEEEXXXX((((1111))))             VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))              FFFFLLLLEEEEXXXX((((1111))))
  2447.  
  2448.  
  2449.  
  2450.               perf-report     -p option
  2451.               read            -Cr option
  2452.               stdout          -t option
  2453.               verbose         -v option
  2454.               warn            opposite of -w option
  2455.                               (use "%option nowarn" for -w)
  2456.  
  2457.               array           equivalent to "%array"
  2458.               pointer         equivalent to "%pointer" (default)
  2459.  
  2460.           Some %%%%ooooppppttttiiiioooonnnn''''ssss provide features otherwise not available:
  2461.  
  2462.           aaaallllwwwwaaaayyyyssss----iiiinnnntttteeeerrrraaaaccccttttiiiivvvveeee
  2463.                instructs flex to generate a scanner which always
  2464.                considers its input "interactive".  Normally, on each
  2465.                new input file the scanner calls iiiissssaaaattttttttyyyy(((()))) in an attempt
  2466.                to determine whether the scanner's input source is
  2467.                interactive and thus should be read a character at a
  2468.                time.  When this option is used, however, then no such
  2469.                call is made.
  2470.  
  2471.           mmmmaaaaiiiinnnn directs flex to provide a default mmmmaaaaiiiinnnn(((()))) program for
  2472.                the scanner, which simply calls yyyyyyyylllleeeexxxx(((()))).... This option
  2473.                implies nnnnooooyyyyyyyywwwwrrrraaaapppp (see below).
  2474.  
  2475.           nnnneeeevvvveeeerrrr----iiiinnnntttteeeerrrraaaaccccttttiiiivvvveeee
  2476.                instructs flex to generate a scanner which never
  2477.                considers its input "interactive" (again, no call made
  2478.                to iiiissssaaaattttttttyyyy(((()))))))).... This is the opposite of aaaallllwwwwaaaayyyyssss----
  2479.                iiiinnnntttteeeerrrraaaaccccttttiiiivvvveeee....
  2480.  
  2481.           ssssttttaaaacccckkkk
  2482.                enables the use of start condition stacks (see Start
  2483.                Conditions above).
  2484.  
  2485.           ssssttttddddiiiinnnniiiitttt
  2486.                if set (i.e., %%%%ooooppppttttiiiioooonnnn ssssttttddddiiiinnnniiiitttt)))) initializes _y_y_i_n and
  2487.                _y_y_o_u_t to _s_t_d_i_n and _s_t_d_o_u_t, instead of the default of
  2488.                _n_i_l. Some existing _l_e_x programs depend on this
  2489.                behavior, even though it is not compliant with ANSI C,
  2490.                which does not require _s_t_d_i_n and _s_t_d_o_u_t to be compile-
  2491.                time constant.
  2492.  
  2493.           yyyyyyyylllliiiinnnneeeennnnoooo
  2494.                directs _f_l_e_x to generate a scanner that maintains the
  2495.                number of the current line read from its input in the
  2496.                global variable yyyyyyyylllliiiinnnneeeennnnoooo.... This option is implied by
  2497.                %%%%ooooppppttttiiiioooonnnn lllleeeexxxx----ccccoooommmmppppaaaatttt....
  2498.  
  2499.           yyyyyyyywwwwrrrraaaapppp
  2500.                if unset (i.e., %%%%ooooppppttttiiiioooonnnn nnnnooooyyyyyyyywwwwrrrraaaapppp)))),,,, makes the scanner
  2501.                not call yyyyyyyywwwwrrrraaaapppp(((()))) upon an end-of-file, but simply
  2502.  
  2503.  
  2504.  
  2505.      Page 38                                         (printed 10/3/02)
  2506.  
  2507.  
  2508.  
  2509.  
  2510.  
  2511.  
  2512.      FFFFLLLLEEEEXXXX((((1111))))             VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))              FFFFLLLLEEEEXXXX((((1111))))
  2513.  
  2514.  
  2515.  
  2516.                assume that there are no more files to scan (until the
  2517.                user points _y_y_i_n at a new file and calls yyyyyyyylllleeeexxxx(((())))
  2518.                again).
  2519.  
  2520.           _f_l_e_x scans your rule actions to determine whether you use
  2521.           the RRRREEEEJJJJEEEECCCCTTTT or yyyyyyyymmmmoooorrrreeee(((()))) features.  The rrrreeeejjjjeeeecccctttt and yyyyyyyymmmmoooorrrreeee
  2522.           options are available to override its decision as to whether
  2523.           you use the options, either by setting them (e.g., %%%%ooooppppttttiiiioooonnnn
  2524.           rrrreeeejjjjeeeecccctttt)))) to indicate the feature is indeed used, or unsetting
  2525.           them to indicate it actually is not used (e.g., %%%%ooooppppttttiiiioooonnnn
  2526.           nnnnooooyyyyyyyymmmmoooorrrreeee))))....
  2527.  
  2528.           Three options take string-delimited values, offset with '=':
  2529.  
  2530.               %option outfile="ABC"
  2531.  
  2532.           is equivalent to ----ooooAAAABBBBCCCC,,,, and
  2533.  
  2534.               %option prefix="XYZ"
  2535.  
  2536.           is equivalent to ----PPPPXXXXYYYYZZZZ.... Finally,
  2537.  
  2538.               %option yyclass="foo"
  2539.  
  2540.           only applies when generating a C++ scanner ( ----++++ option).  It
  2541.           informs _f_l_e_x that you have derived ffffoooooooo as a subclass of
  2542.           yyyyyyyyFFFFlllleeeexxxxLLLLeeeexxxxeeeerrrr,,,, so _f_l_e_x will place your actions in the member
  2543.           function ffffoooooooo::::::::yyyyyyyylllleeeexxxx(((()))) instead of yyyyyyyyFFFFlllleeeexxxxLLLLeeeexxxxeeeerrrr::::::::yyyyyyyylllleeeexxxx(((()))).... It
  2544.           also generates a yyyyyyyyFFFFlllleeeexxxxLLLLeeeexxxxeeeerrrr::::::::yyyyyyyylllleeeexxxx(((()))) member function that
  2545.           emits a run-time error (by invoking
  2546.           yyyyyyyyFFFFlllleeeexxxxLLLLeeeexxxxeeeerrrr::::::::LLLLeeeexxxxeeeerrrrEEEErrrrrrrroooorrrr(((()))))))) if called.  See Generating C++
  2547.           Scanners, below, for additional information.
  2548.  
  2549.           A number of options are available for lint purists who want
  2550.           to suppress the appearance of unneeded routines in the
  2551.           generated scanner.  Each of the following, if unset (e.g.,
  2552.           %%%%ooooppppttttiiiioooonnnn nnnnoooouuuunnnnppppuuuutttt ), results in the corresponding routine not
  2553.           appearing in the generated scanner:
  2554.  
  2555.               input, unput
  2556.               yy_push_state, yy_pop_state, yy_top_state
  2557.               yy_scan_buffer, yy_scan_bytes, yy_scan_string
  2558.  
  2559.           (though yyyyyyyy____ppppuuuusssshhhh____ssssttttaaaatttteeee(((()))) and friends won't appear anyway
  2560.           unless you use %%%%ooooppppttttiiiioooonnnn ssssttttaaaacccckkkk))))....
  2561.  
  2562.      PPPPEEEERRRRFFFFOOOORRRRMMMMAAAANNNNCCCCEEEE CCCCOOOONNNNSSSSIIIIDDDDEEEERRRRAAAATTTTIIIIOOOONNNNSSSS
  2563.           The main design goal of _f_l_e_x is that it generate high-
  2564.           performance scanners.  It has been optimized for dealing
  2565.           well with large sets of rules.  Aside from the effects on
  2566.           scanner speed of the table compression ----CCCC options outlined
  2567.           above, there are a number of options/actions which degrade
  2568.  
  2569.  
  2570.  
  2571.      Page 39                                         (printed 10/3/02)
  2572.  
  2573.  
  2574.  
  2575.  
  2576.  
  2577.  
  2578.      FFFFLLLLEEEEXXXX((((1111))))             VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))              FFFFLLLLEEEEXXXX((((1111))))
  2579.  
  2580.  
  2581.  
  2582.           performance.  These are, from most expensive to least:
  2583.  
  2584.               REJECT
  2585.               %option yylineno
  2586.               arbitrary trailing context
  2587.  
  2588.               pattern sets that require backing up
  2589.               %array
  2590.               %option interactive
  2591.               %option always-interactive
  2592.  
  2593.               '^' beginning-of-line operator
  2594.               yymore()
  2595.  
  2596.           with the first three all being quite expensive and the last
  2597.           two being quite cheap.  Note also that uuuunnnnppppuuuutttt(((()))) is
  2598.           implemented as a routine call that potentially does quite a
  2599.           bit of work, while yyyyyyyylllleeeessssssss(((()))) is a quite-cheap macro; so if
  2600.           just putting back some excess text you scanned, use
  2601.           yyyyyyyylllleeeessssssss(((())))....
  2602.  
  2603.           RRRREEEEJJJJEEEECCCCTTTT should be avoided at all costs when performance is
  2604.           important.  It is a particularly expensive option.
  2605.  
  2606.           Getting rid of backing up is messy and often may be an
  2607.           enormous amount of work for a complicated scanner.  In
  2608.           principal, one begins by using the ----bbbb flag to generate a
  2609.           _l_e_x._b_a_c_k_u_p file.  For example, on the input
  2610.  
  2611.               %%
  2612.               foo        return TOK_KEYWORD;
  2613.               foobar     return TOK_KEYWORD;
  2614.  
  2615.           the file looks like:
  2616.  
  2617.               State #6 is non-accepting -
  2618.                associated rule line numbers:
  2619.                      2       3
  2620.                out-transitions: [ o ]
  2621.                jam-transitions: EOF [ \001-n  p-\177 ]
  2622.  
  2623.               State #8 is non-accepting -
  2624.                associated rule line numbers:
  2625.                      3
  2626.                out-transitions: [ a ]
  2627.                jam-transitions: EOF [ \001-`  b-\177 ]
  2628.  
  2629.               State #9 is non-accepting -
  2630.                associated rule line numbers:
  2631.                      3
  2632.                out-transitions: [ r ]
  2633.                jam-transitions: EOF [ \001-q  s-\177 ]
  2634.  
  2635.  
  2636.  
  2637.      Page 40                                         (printed 10/3/02)
  2638.  
  2639.  
  2640.  
  2641.  
  2642.  
  2643.  
  2644.      FFFFLLLLEEEEXXXX((((1111))))             VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))              FFFFLLLLEEEEXXXX((((1111))))
  2645.  
  2646.  
  2647.  
  2648.               Compressed tables always back up.
  2649.  
  2650.           The first few lines tell us that there's a scanner state in
  2651.           which it can make a transition on an 'o' but not on any
  2652.           other character, and that in that state the currently
  2653.           scanned text does not match any rule.  The state occurs when
  2654.           trying to match the rules found at lines 2 and 3 in the
  2655.           input file.  If the scanner is in that state and then reads
  2656.           something other than an 'o', it will have to back up to find
  2657.           a rule which is matched.  With a bit of headscratching one
  2658.           can see that this must be the state it's in when it has seen
  2659.           "fo".  When this has happened, if anything other than
  2660.           another 'o' is seen, the scanner will have to back up to
  2661.           simply match the 'f' (by the default rule).
  2662.  
  2663.           The comment regarding State #8 indicates there's a problem
  2664.           when "foob" has been scanned.  Indeed, on any character
  2665.           other than an 'a', the scanner will have to back up to
  2666.           accept "foo".  Similarly, the comment for State #9 concerns
  2667.           when "fooba" has been scanned and an 'r' does not follow.
  2668.  
  2669.           The final comment reminds us that there's no point going to
  2670.           all the trouble of removing backing up from the rules unless
  2671.           we're using ----CCCCffff or ----CCCCFFFF,,,, since there's no performance gain
  2672.           doing so with compressed scanners.
  2673.  
  2674.           The way to remove the backing up is to add "error" rules:
  2675.  
  2676.               %%
  2677.               foo         return TOK_KEYWORD;
  2678.               foobar      return TOK_KEYWORD;
  2679.  
  2680.               fooba       |
  2681.               foob        |
  2682.               fo          {
  2683.                           /* false alarm, not really a keyword */
  2684.                           return TOK_ID;
  2685.                           }
  2686.  
  2687.  
  2688.           Eliminating backing up among a list of keywords can also be
  2689.           done using a "catch-all" rule:
  2690.  
  2691.               %%
  2692.               foo         return TOK_KEYWORD;
  2693.               foobar      return TOK_KEYWORD;
  2694.  
  2695.               [a-z]+      return TOK_ID;
  2696.  
  2697.           This is usually the best solution when appropriate.
  2698.  
  2699.           Backing up messages tend to cascade.  With a complicated set
  2700.  
  2701.  
  2702.  
  2703.      Page 41                                         (printed 10/3/02)
  2704.  
  2705.  
  2706.  
  2707.  
  2708.  
  2709.  
  2710.      FFFFLLLLEEEEXXXX((((1111))))             VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))              FFFFLLLLEEEEXXXX((((1111))))
  2711.  
  2712.  
  2713.  
  2714.           of rules it's not uncommon to get hundreds of messages.  If
  2715.           one can decipher them, though, it often only takes a dozen
  2716.           or so rules to eliminate the backing up (though it's easy to
  2717.           make a mistake and have an error rule accidentally match a
  2718.           valid token.  A possible future _f_l_e_x feature will be to
  2719.           automatically add rules to eliminate backing up).
  2720.  
  2721.           It's important to keep in mind that you gain the benefits of
  2722.           eliminating backing up only if you eliminate _e_v_e_r_y instance
  2723.           of backing up.  Leaving just one means you gain nothing.
  2724.  
  2725.           _V_a_r_i_a_b_l_e trailing context (where both the leading and
  2726.           trailing parts do not have a fixed length) entails almost
  2727.           the same performance loss as RRRREEEEJJJJEEEECCCCTTTT (i.e., substantial).  So
  2728.           when possible a rule like:
  2729.  
  2730.               %%
  2731.               mouse|rat/(cat|dog)   run();
  2732.  
  2733.           is better written:
  2734.  
  2735.               %%
  2736.               mouse/cat|dog         run();
  2737.               rat/cat|dog           run();
  2738.  
  2739.           or as
  2740.  
  2741.               %%
  2742.               mouse|rat/cat         run();
  2743.               mouse|rat/dog         run();
  2744.  
  2745.           Note that here the special '|' action does _n_o_t provide any
  2746.           savings, and can even make things worse (see Deficiencies /
  2747.           Bugs below).
  2748.  
  2749.           Another area where the user can increase a scanner's
  2750.           performance (and one that's easier to implement) arises from
  2751.           the fact that the longer the tokens matched, the faster the
  2752.           scanner will run.  This is because with long tokens the
  2753.           processing of most input characters takes place in the
  2754.           (short) inner scanning loop, and does not often have to go
  2755.           through the additional work of setting up the scanning
  2756.           environment (e.g., yyyyyyyytttteeeexxxxtttt)))) for the action.  Recall the
  2757.           scanner for C comments:
  2758.  
  2759.               %x comment
  2760.               %%
  2761.                       int line_num = 1;
  2762.  
  2763.               "/*"         BEGIN(comment);
  2764.  
  2765.               <comment>[^*\n]*
  2766.  
  2767.  
  2768.  
  2769.      Page 42                                         (printed 10/3/02)
  2770.  
  2771.  
  2772.  
  2773.  
  2774.  
  2775.  
  2776.      FFFFLLLLEEEEXXXX((((1111))))             VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))              FFFFLLLLEEEEXXXX((((1111))))
  2777.  
  2778.  
  2779.  
  2780.               <comment>"*"+[^*/\n]*
  2781.               <comment>\n             ++line_num;
  2782.               <comment>"*"+"/"        BEGIN(INITIAL);
  2783.  
  2784.           This could be sped up by writing it as:
  2785.  
  2786.               %x comment
  2787.               %%
  2788.                       int line_num = 1;
  2789.  
  2790.               "/*"         BEGIN(comment);
  2791.  
  2792.               <comment>[^*\n]*
  2793.               <comment>[^*\n]*\n      ++line_num;
  2794.               <comment>"*"+[^*/\n]*
  2795.               <comment>"*"+[^*/\n]*\n ++line_num;
  2796.               <comment>"*"+"/"        BEGIN(INITIAL);
  2797.  
  2798.           Now instead of each newline requiring the processing of
  2799.           another action, recognizing the newlines is "distributed"
  2800.           over the other rules to keep the matched text as long as
  2801.           possible.  Note that _a_d_d_i_n_g rules does _n_o_t slow down the
  2802.           scanner!  The speed of the scanner is independent of the
  2803.           number of rules or (modulo the considerations given at the
  2804.           beginning of this section) how complicated the rules are
  2805.           with regard to operators such as '*' and '|'.
  2806.  
  2807.           A final example in speeding up a scanner: suppose you want
  2808.           to scan through a file containing identifiers and keywords,
  2809.           one per line and with no other extraneous characters, and
  2810.           recognize all the keywords.  A natural first approach is:
  2811.  
  2812.               %%
  2813.               asm      |
  2814.               auto     |
  2815.               break    |
  2816.               ... etc ...
  2817.               volatile |
  2818.               while    /* it's a keyword */
  2819.  
  2820.               .|\n     /* it's not a keyword */
  2821.  
  2822.           To eliminate the back-tracking, introduce a catch-all rule:
  2823.  
  2824.               %%
  2825.               asm      |
  2826.               auto     |
  2827.               break    |
  2828.               ... etc ...
  2829.               volatile |
  2830.               while    /* it's a keyword */
  2831.  
  2832.  
  2833.  
  2834.  
  2835.      Page 43                                         (printed 10/3/02)
  2836.  
  2837.  
  2838.  
  2839.  
  2840.  
  2841.  
  2842.      FFFFLLLLEEEEXXXX((((1111))))             VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))              FFFFLLLLEEEEXXXX((((1111))))
  2843.  
  2844.  
  2845.  
  2846.               [a-z]+   |
  2847.               .|\n     /* it's not a keyword */
  2848.  
  2849.           Now, if it's guaranteed that there's exactly one word per
  2850.           line, then we can reduce the total number of matches by a
  2851.           half by merging in the recognition of newlines with that of
  2852.           the other tokens:
  2853.  
  2854.               %%
  2855.               asm\n    |
  2856.               auto\n   |
  2857.               break\n  |
  2858.               ... etc ...
  2859.               volatile\n |
  2860.               while\n  /* it's a keyword */
  2861.  
  2862.               [a-z]+\n |
  2863.               .|\n     /* it's not a keyword */
  2864.  
  2865.           One has to be careful here, as we have now reintroduced
  2866.           backing up into the scanner.  In particular, while _w_e know
  2867.           that there will never be any characters in the input stream
  2868.           other than letters or newlines, _f_l_e_x can't figure this out,
  2869.           and it will plan for possibly needing to back up when it has
  2870.           scanned a token like "auto" and then the next character is
  2871.           something other than a newline or a letter.  Previously it
  2872.           would then just match the "auto" rule and be done, but now
  2873.           it has no "auto" rule, only a "auto\n" rule.  To eliminate
  2874.           the possibility of backing up, we could either duplicate all
  2875.           rules but without final newlines, or, since we never expect
  2876.           to encounter such an input and therefore don't how it's
  2877.           classified, we can introduce one more catch-all rule, this
  2878.           one which doesn't include a newline:
  2879.  
  2880.               %%
  2881.               asm\n    |
  2882.               auto\n   |
  2883.               break\n  |
  2884.               ... etc ...
  2885.               volatile\n |
  2886.               while\n  /* it's a keyword */
  2887.  
  2888.               [a-z]+\n |
  2889.               [a-z]+   |
  2890.               .|\n     /* it's not a keyword */
  2891.  
  2892.           Compiled with ----CCCCffff,,,, this is about as fast as one can get a
  2893.           _f_l_e_x scanner to go for this particular problem.
  2894.  
  2895.           A final note:  _f_l_e_x is slow when matching NUL's,
  2896.           particularly when a token contains multiple NUL's.  It's
  2897.           best to write rules which match _s_h_o_r_t amounts of text if
  2898.  
  2899.  
  2900.  
  2901.      Page 44                                         (printed 10/3/02)
  2902.  
  2903.  
  2904.  
  2905.  
  2906.  
  2907.  
  2908.      FFFFLLLLEEEEXXXX((((1111))))             VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))              FFFFLLLLEEEEXXXX((((1111))))
  2909.  
  2910.  
  2911.  
  2912.           it's anticipated that the text will often include NUL's.
  2913.  
  2914.           Another final note regarding performance: as mentioned above
  2915.           in the section How the Input is Matched, dynamically
  2916.           resizing yyyyyyyytttteeeexxxxtttt to accommodate huge tokens is a slow process
  2917.           because it presently requires that the (huge) token be
  2918.           rescanned from the beginning.  Thus if performance is vital,
  2919.           you should attempt to match "large" quantities of text but
  2920.           not "huge" quantities, where the cutoff between the two is
  2921.           at about 8K characters/token.
  2922.  
  2923.      GGGGEEEENNNNEEEERRRRAAAATTTTIIIINNNNGGGG CCCC++++++++ SSSSCCCCAAAANNNNNNNNEEEERRRRSSSS
  2924.           _f_l_e_x provides two different ways to generate scanners for
  2925.           use with C++.  The first way is to simply compile a scanner
  2926.           generated by _f_l_e_x using a C++ compiler instead of a C
  2927.           compiler.  You should not encounter any compilations errors
  2928.           (please report any you find to the email address given in
  2929.           the Author section below).  You can then use C++ code in
  2930.           your rule actions instead of C code.  Note that the default
  2931.           input source for your scanner remains _y_y_i_n, and default
  2932.           echoing is still done to _y_y_o_u_t. Both of these remain _F_I_L_E *
  2933.           variables and not C++ _s_t_r_e_a_m_s.
  2934.  
  2935.           You can also use _f_l_e_x to generate a C++ scanner class, using
  2936.           the ----++++ option (or, equivalently, %%%%ooooppppttttiiiioooonnnn cccc++++++++)))),,,, which is
  2937.           automatically specified if the name of the flex executable
  2938.           ends in a '+', such as _f_l_e_x++. When using this option, flex
  2939.           defaults to generating the scanner to the file lllleeeexxxx....yyyyyyyy....cccccccc
  2940.           instead of lllleeeexxxx....yyyyyyyy....cccc.... The generated scanner includes the
  2941.           header file _F_l_e_x_L_e_x_e_r._h, which defines the interface to two
  2942.           C++ classes.
  2943.  
  2944.           The first class, FFFFlllleeeexxxxLLLLeeeexxxxeeeerrrr,,,, provides an abstract base class
  2945.           defining the general scanner class interface.  It provides
  2946.           the following member functions:
  2947.  
  2948.           ccccoooonnnnsssstttt cccchhhhaaaarrrr**** YYYYYYYYTTTTeeeexxxxtttt(((())))
  2949.                returns the text of the most recently matched token,
  2950.                the equivalent of yyyyyyyytttteeeexxxxtttt....
  2951.  
  2952.           iiiinnnntttt YYYYYYYYLLLLeeeennnngggg(((())))
  2953.                returns the length of the most recently matched token,
  2954.                the equivalent of yyyyyyyylllleeeennnngggg....
  2955.  
  2956.           iiiinnnntttt lllliiiinnnneeeennnnoooo(((()))) ccccoooonnnnsssstttt
  2957.                returns the current input line number (see %%%%ooooppppttttiiiioooonnnn
  2958.                yyyyyyyylllliiiinnnneeeennnnoooo)))),,,, or 1111 if %%%%ooooppppttttiiiioooonnnn yyyyyyyylllliiiinnnneeeennnnoooo was not used.
  2959.  
  2960.           vvvvooooiiiidddd sssseeeetttt____ddddeeeebbbbuuuugggg(((( iiiinnnntttt ffffllllaaaagggg ))))
  2961.                sets the debugging flag for the scanner, equivalent to
  2962.                assigning to yyyyyyyy____fffflllleeeexxxx____ddddeeeebbbbuuuugggg (see the Options section
  2963.                above).  Note that you must build the scanner using
  2964.  
  2965.  
  2966.  
  2967.      Page 45                                         (printed 10/3/02)
  2968.  
  2969.  
  2970.  
  2971.  
  2972.  
  2973.  
  2974.      FFFFLLLLEEEEXXXX((((1111))))             VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))              FFFFLLLLEEEEXXXX((((1111))))
  2975.  
  2976.  
  2977.  
  2978.                %%%%ooooppppttttiiiioooonnnn ddddeeeebbbbuuuugggg to include debugging information in it.
  2979.  
  2980.           iiiinnnntttt ddddeeeebbbbuuuugggg(((()))) ccccoooonnnnsssstttt
  2981.                returns the current setting of the debugging flag.
  2982.  
  2983.           Also provided are member functions equivalent to
  2984.           yyyyyyyy____sssswwwwiiiittttcccchhhh____ttttoooo____bbbbuuuuffffffffeeeerrrr(((()))),,,, yyyyyyyy____ccccrrrreeeeaaaatttteeee____bbbbuuuuffffffffeeeerrrr(((()))) (though the first
  2985.           argument is an iiiissssttttrrrreeeeaaaammmm**** object pointer and not a FFFFIIIILLLLEEEE****)))),,,,
  2986.           yyyyyyyy____fffflllluuuusssshhhh____bbbbuuuuffffffffeeeerrrr(((()))),,,, yyyyyyyy____ddddeeeelllleeeetttteeee____bbbbuuuuffffffffeeeerrrr(((()))),,,, and yyyyyyyyrrrreeeessssttttaaaarrrrtttt(((())))
  2987.           (again, the first argument is a iiiissssttttrrrreeeeaaaammmm**** object pointer).
  2988.  
  2989.           The second class defined in _F_l_e_x_L_e_x_e_r._h is yyyyyyyyFFFFlllleeeexxxxLLLLeeeexxxxeeeerrrr,,,,
  2990.           which is derived from FFFFlllleeeexxxxLLLLeeeexxxxeeeerrrr.... It defines the following
  2991.           additional member functions:
  2992.  
  2993.           yyyyyyyyFFFFlllleeeexxxxLLLLeeeexxxxeeeerrrr(((( iiiissssttttrrrreeeeaaaammmm**** aaaarrrrgggg____yyyyyyyyiiiinnnn ==== 0000,,,, oooossssttttrrrreeeeaaaammmm**** aaaarrrrgggg____yyyyyyyyoooouuuutttt ==== 0000 ))))
  2994.                constructs a yyyyyyyyFFFFlllleeeexxxxLLLLeeeexxxxeeeerrrr object using the given streams
  2995.                for input and output.  If not specified, the streams
  2996.                default to cccciiiinnnn and ccccoooouuuutttt,,,, respectively.
  2997.  
  2998.           vvvviiiirrrrttttuuuuaaaallll iiiinnnntttt yyyyyyyylllleeeexxxx(((())))
  2999.                performs the same role is yyyyyyyylllleeeexxxx(((()))) does for ordinary
  3000.                flex scanners: it scans the input stream, consuming
  3001.                tokens, until a rule's action returns a value.  If you
  3002.                derive a subclass SSSS from yyyyyyyyFFFFlllleeeexxxxLLLLeeeexxxxeeeerrrr and want to access
  3003.                the member functions and variables of SSSS inside yyyyyyyylllleeeexxxx(((()))),,,,
  3004.                then you need to use %%%%ooooppppttttiiiioooonnnn yyyyyyyyccccllllaaaassssssss====""""SSSS"""" to inform _f_l_e_x
  3005.                that you will be using that subclass instead of
  3006.                yyyyyyyyFFFFlllleeeexxxxLLLLeeeexxxxeeeerrrr.... In this case, rather than generating
  3007.                yyyyyyyyFFFFlllleeeexxxxLLLLeeeexxxxeeeerrrr::::::::yyyyyyyylllleeeexxxx(((()))),,,, _f_l_e_x generates SSSS::::::::yyyyyyyylllleeeexxxx(((()))) (and
  3008.                also generates a dummy yyyyyyyyFFFFlllleeeexxxxLLLLeeeexxxxeeeerrrr::::::::yyyyyyyylllleeeexxxx(((()))) that calls
  3009.                yyyyyyyyFFFFlllleeeexxxxLLLLeeeexxxxeeeerrrr::::::::LLLLeeeexxxxeeeerrrrEEEErrrrrrrroooorrrr(((()))) if called).
  3010.  
  3011.           vvvviiiirrrrttttuuuuaaaallll vvvvooooiiiidddd sssswwwwiiiittttcccchhhh____ssssttttrrrreeeeaaaammmmssss((((iiiissssttttrrrreeeeaaaammmm**** nnnneeeewwww____iiiinnnn ==== 0000,,,,
  3012.                oooossssttttrrrreeeeaaaammmm**** nnnneeeewwww____oooouuuutttt ==== 0000)))) reassigns yyyyyyyyiiiinnnn to nnnneeeewwww____iiiinnnn (if
  3013.                non-nil) and yyyyyyyyoooouuuutttt to nnnneeeewwww____oooouuuutttt (ditto), deleting the
  3014.                previous input buffer if yyyyyyyyiiiinnnn is reassigned.
  3015.  
  3016.           iiiinnnntttt yyyyyyyylllleeeexxxx(((( iiiissssttttrrrreeeeaaaammmm**** nnnneeeewwww____iiiinnnn,,,, oooossssttttrrrreeeeaaaammmm**** nnnneeeewwww____oooouuuutttt ==== 0000 ))))
  3017.                first switches the input streams via sssswwwwiiiittttcccchhhh____ssssttttrrrreeeeaaaammmmssss((((
  3018.                nnnneeeewwww____iiiinnnn,,,, nnnneeeewwww____oooouuuutttt )))) and then returns the value of
  3019.                yyyyyyyylllleeeexxxx(((())))....
  3020.  
  3021.           In addition, yyyyyyyyFFFFlllleeeexxxxLLLLeeeexxxxeeeerrrr defines the following protected
  3022.           virtual functions which you can redefine in derived classes
  3023.           to tailor the scanner:
  3024.  
  3025.           vvvviiiirrrrttttuuuuaaaallll iiiinnnntttt LLLLeeeexxxxeeeerrrrIIIInnnnppppuuuutttt(((( cccchhhhaaaarrrr**** bbbbuuuuffff,,,, iiiinnnntttt mmmmaaaaxxxx____ssssiiiizzzzeeee ))))
  3026.                reads up to mmmmaaaaxxxx____ssssiiiizzzzeeee characters into bbbbuuuuffff and returns
  3027.                the number of characters read.  To indicate end-of-
  3028.                input, return 0 characters.  Note that "interactive"
  3029.                scanners (see the ----BBBB and ----IIII flags) define the macro
  3030.  
  3031.  
  3032.  
  3033.      Page 46                                         (printed 10/3/02)
  3034.  
  3035.  
  3036.  
  3037.  
  3038.  
  3039.  
  3040.      FFFFLLLLEEEEXXXX((((1111))))             VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))              FFFFLLLLEEEEXXXX((((1111))))
  3041.  
  3042.  
  3043.  
  3044.                YYYYYYYY____IIIINNNNTTTTEEEERRRRAAAACCCCTTTTIIIIVVVVEEEE.... If you redefine LLLLeeeexxxxeeeerrrrIIIInnnnppppuuuutttt(((()))) and need
  3045.                to take different actions depending on whether or not
  3046.                the scanner might be scanning an interactive input
  3047.                source, you can test for the presence of this name via
  3048.                ####iiiiffffddddeeeeffff....
  3049.  
  3050.           vvvviiiirrrrttttuuuuaaaallll vvvvooooiiiidddd LLLLeeeexxxxeeeerrrrOOOOuuuuttttppppuuuutttt(((( ccccoooonnnnsssstttt cccchhhhaaaarrrr**** bbbbuuuuffff,,,, iiiinnnntttt ssssiiiizzzzeeee ))))
  3051.                writes out ssssiiiizzzzeeee characters from the buffer bbbbuuuuffff,,,, which,
  3052.                while NUL-terminated, may also contain "internal" NUL's
  3053.                if the scanner's rules can match text with NUL's in
  3054.                them.
  3055.  
  3056.           vvvviiiirrrrttttuuuuaaaallll vvvvooooiiiidddd LLLLeeeexxxxeeeerrrrEEEErrrrrrrroooorrrr(((( ccccoooonnnnsssstttt cccchhhhaaaarrrr**** mmmmssssgggg ))))
  3057.                reports a fatal error message.  The default version of
  3058.                this function writes the message to the stream cccceeeerrrrrrrr and
  3059.                exits.
  3060.  
  3061.           Note that a yyyyyyyyFFFFlllleeeexxxxLLLLeeeexxxxeeeerrrr object contains its _e_n_t_i_r_e scanning
  3062.           state.  Thus you can use such objects to create reentrant
  3063.           scanners.  You can instantiate multiple instances of the
  3064.           same yyyyyyyyFFFFlllleeeexxxxLLLLeeeexxxxeeeerrrr class, and you can also combine multiple
  3065.           C++ scanner classes together in the same program using the
  3066.           ----PPPP option discussed above.
  3067.  
  3068.           Finally, note that the %%%%aaaarrrrrrrraaaayyyy feature is not available to
  3069.           C++ scanner classes; you must use %%%%ppppooooiiiinnnntttteeeerrrr (the default).
  3070.  
  3071.           Here is an example of a simple C++ scanner:
  3072.  
  3073.                   // An example of using the flex C++ scanner class.
  3074.  
  3075.               %{
  3076.               int mylineno = 0;
  3077.               %}
  3078.  
  3079.               string  \"[^\n"]+\"
  3080.  
  3081.               ws      [ \t]+
  3082.  
  3083.               alpha   [A-Za-z]
  3084.               dig     [0-9]
  3085.               name    ({alpha}|{dig}|\$)({alpha}|{dig}|[_.\-/$])*
  3086.               num1    [-+]?{dig}+\.?([eE][-+]?{dig}+)?
  3087.               num2    [-+]?{dig}*\.{dig}+([eE][-+]?{dig}+)?
  3088.               number  {num1}|{num2}
  3089.  
  3090.               %%
  3091.  
  3092.               {ws}    /* skip blanks and tabs */
  3093.  
  3094.               "/*"    {
  3095.                       int c;
  3096.  
  3097.  
  3098.  
  3099.      Page 47                                         (printed 10/3/02)
  3100.  
  3101.  
  3102.  
  3103.  
  3104.  
  3105.  
  3106.      FFFFLLLLEEEEXXXX((((1111))))             VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))              FFFFLLLLEEEEXXXX((((1111))))
  3107.  
  3108.  
  3109.  
  3110.                       while((c = yyinput()) != 0)
  3111.                           {
  3112.                           if(c == '\n')
  3113.                               ++mylineno;
  3114.  
  3115.                           else if(c == '*')
  3116.                               {
  3117.                               if((c = yyinput()) == '/')
  3118.                                   break;
  3119.                               else
  3120.                                   unput(c);
  3121.                               }
  3122.                           }
  3123.                       }
  3124.  
  3125.               {number}  cout << "number " << YYText() << '\n';
  3126.  
  3127.               \n        mylineno++;
  3128.  
  3129.               {name}    cout << "name " << YYText() << '\n';
  3130.  
  3131.               {string}  cout << "string " << YYText() << '\n';
  3132.  
  3133.               %%
  3134.  
  3135.               int main( int /* argc */, char** /* argv */ )
  3136.                   {
  3137.                   FlexLexer* lexer = new yyFlexLexer;
  3138.                   while(lexer->yylex() != 0)
  3139.                       ;
  3140.                   return 0;
  3141.                   }
  3142.           If you want to create multiple (different) lexer classes,
  3143.           you use the ----PPPP flag (or the pppprrrreeeeffffiiiixxxx==== option) to rename each
  3144.           yyyyyyyyFFFFlllleeeexxxxLLLLeeeexxxxeeeerrrr to some other xxxxxxxxFFFFlllleeeexxxxLLLLeeeexxxxeeeerrrr.... You then can include
  3145.           <<<<FFFFlllleeeexxxxLLLLeeeexxxxeeeerrrr....hhhh>>>> in your other sources once per lexer class,
  3146.           first renaming yyyyyyyyFFFFlllleeeexxxxLLLLeeeexxxxeeeerrrr as follows:
  3147.  
  3148.               #undef yyFlexLexer
  3149.               #define yyFlexLexer xxFlexLexer
  3150.               #include <FlexLexer.h>
  3151.  
  3152.               #undef yyFlexLexer
  3153.               #define yyFlexLexer zzFlexLexer
  3154.               #include <FlexLexer.h>
  3155.  
  3156.           if, for example, you used %%%%ooooppppttttiiiioooonnnn pppprrrreeeeffffiiiixxxx====""""xxxxxxxx"""" for one of
  3157.           your scanners and %%%%ooooppppttttiiiioooonnnn pppprrrreeeeffffiiiixxxx====""""zzzzzzzz"""" for the other.
  3158.  
  3159.           IMPORTANT: the present form of the scanning class is
  3160.           _e_x_p_e_r_i_m_e_n_t_a_l and may change considerably between major
  3161.           releases.
  3162.  
  3163.  
  3164.  
  3165.      Page 48                                         (printed 10/3/02)
  3166.  
  3167.  
  3168.  
  3169.  
  3170.  
  3171.  
  3172.      FFFFLLLLEEEEXXXX((((1111))))             VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))              FFFFLLLLEEEEXXXX((((1111))))
  3173.  
  3174.  
  3175.  
  3176.      IIIINNNNCCCCOOOOMMMMPPPPAAAATTTTIIIIBBBBIIIILLLLIIIITTTTIIIIEEEESSSS WWWWIIIITTTTHHHH LLLLEEEEXXXX AAAANNNNDDDD PPPPOOOOSSSSIIIIXXXX
  3177.           _f_l_e_x is a rewrite of the AT&T Unix _l_e_x tool (the two
  3178.           implementations do not share any code, though), with some
  3179.           extensions and incompatibilities, both of which are of
  3180.           concern to those who wish to write scanners acceptable to
  3181.           either implementation.  Flex is fully compliant with the
  3182.           POSIX _l_e_x specification, except that when using %%%%ppppooooiiiinnnntttteeeerrrr
  3183.           (the default), a call to uuuunnnnppppuuuutttt(((()))) destroys the contents of
  3184.           yyyyyyyytttteeeexxxxtttt,,,, which is counter to the POSIX specification.
  3185.  
  3186.           In this section we discuss all of the known areas of
  3187.           incompatibility between flex, AT&T lex, and the POSIX
  3188.           specification.
  3189.  
  3190.           _f_l_e_x'_s ----llll option turns on maximum compatibility with the
  3191.           original AT&T _l_e_x implementation, at the cost of a major
  3192.           loss in the generated scanner's performance.  We note below
  3193.           which incompatibilities can be overcome using the ----llll option.
  3194.  
  3195.           _f_l_e_x is fully compatible with _l_e_x with the following
  3196.           exceptions:
  3197.  
  3198.           -    The undocumented _l_e_x scanner internal variable yyyyyyyylllliiiinnnneeeennnnoooo
  3199.                is not supported unless ----llll or %%%%ooooppppttttiiiioooonnnn yyyyyyyylllliiiinnnneeeennnnoooo is used.
  3200.  
  3201.                yyyyyyyylllliiiinnnneeeennnnoooo should be maintained on a per-buffer basis,
  3202.                rather than a per-scanner (single global variable)
  3203.                basis.
  3204.  
  3205.                yyyyyyyylllliiiinnnneeeennnnoooo is not part of the POSIX specification.
  3206.  
  3207.           -    The iiiinnnnppppuuuutttt(((()))) routine is not redefinable, though it may
  3208.                be called to read characters following whatever has
  3209.                been matched by a rule.  If iiiinnnnppppuuuutttt(((()))) encounters an end-
  3210.                of-file the normal yyyyyyyywwwwrrrraaaapppp(((()))) processing is done.  A
  3211.                ``real'' end-of-file is returned by iiiinnnnppppuuuutttt(((()))) as _E_O_F.
  3212.  
  3213.                Input is instead controlled by defining the YYYYYYYY____IIIINNNNPPPPUUUUTTTT
  3214.                macro.
  3215.  
  3216.                The _f_l_e_x restriction that iiiinnnnppppuuuutttt(((()))) cannot be redefined
  3217.                is in accordance with the POSIX specification, which
  3218.                simply does not specify any way of controlling the
  3219.                scanner's input other than by making an initial
  3220.                assignment to _y_y_i_n.
  3221.  
  3222.           -    The uuuunnnnppppuuuutttt(((()))) routine is not redefinable.  This
  3223.                restriction is in accordance with POSIX.
  3224.  
  3225.           -    _f_l_e_x scanners are not as reentrant as _l_e_x scanners.  In
  3226.                particular, if you have an interactive scanner and an
  3227.                interrupt handler which long-jumps out of the scanner,
  3228.  
  3229.  
  3230.  
  3231.      Page 49                                         (printed 10/3/02)
  3232.  
  3233.  
  3234.  
  3235.  
  3236.  
  3237.  
  3238.      FFFFLLLLEEEEXXXX((((1111))))             VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))              FFFFLLLLEEEEXXXX((((1111))))
  3239.  
  3240.  
  3241.  
  3242.                and the scanner is subsequently called again, you may
  3243.                get the following message:
  3244.  
  3245.                    fatal flex scanner internal error--end of buffer missed
  3246.  
  3247.                To reenter the scanner, first use
  3248.  
  3249.                    yyrestart( yyin );
  3250.  
  3251.                Note that this call will throw away any buffered input;
  3252.                usually this isn't a problem with an interactive
  3253.                scanner.
  3254.  
  3255.                Also note that flex C++ scanner classes _a_r_e reentrant,
  3256.                so if using C++ is an option for you, you should use
  3257.                them instead.  See "Generating C++ Scanners" above for
  3258.                details.
  3259.  
  3260.           -    oooouuuuttttppppuuuutttt(((()))) is not supported.  Output from the EEEECCCCHHHHOOOO macro
  3261.                is done to the file-pointer _y_y_o_u_t (default _s_t_d_o_u_t).
  3262.  
  3263.                oooouuuuttttppppuuuutttt(((()))) is not part of the POSIX specification.
  3264.  
  3265.           -    _l_e_x does not support exclusive start conditions (%x),
  3266.                though they are in the POSIX specification.
  3267.  
  3268.           -    When definitions are expanded, _f_l_e_x encloses them in
  3269.                parentheses.  With lex, the following:
  3270.  
  3271.                    NAME    [A-Z][A-Z0-9]*
  3272.                    %%
  3273.                    foo{NAME}?      printf( "Found it\n" );
  3274.                    %%
  3275.  
  3276.                will not match the string "foo" because when the macro
  3277.                is expanded the rule is equivalent to "foo[A-Z][A-Z0-
  3278.                9]*?"  and the precedence is such that the '?' is
  3279.                associated with "[A-Z0-9]*".  With _f_l_e_x, the rule will
  3280.                be expanded to "foo([A-Z][A-Z0-9]*)?" and so the string
  3281.                "foo" will match.
  3282.  
  3283.                Note that if the definition begins with ^^^^ or ends with
  3284.                $$$$ then it is _n_o_t expanded with parentheses, to allow
  3285.                these operators to appear in definitions without losing
  3286.                their special meanings.  But the <<<<ssss>>>>,,,, ////,,,, and <<<<<<<<EEEEOOOOFFFF>>>>>>>>
  3287.                operators cannot be used in a _f_l_e_x definition.
  3288.  
  3289.                Using ----llll results in the _l_e_x behavior of no parentheses
  3290.                around the definition.
  3291.  
  3292.                The POSIX specification is that the definition be
  3293.                enclosed in parentheses.
  3294.  
  3295.  
  3296.  
  3297.      Page 50                                         (printed 10/3/02)
  3298.  
  3299.  
  3300.  
  3301.  
  3302.  
  3303.  
  3304.      FFFFLLLLEEEEXXXX((((1111))))             VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))              FFFFLLLLEEEEXXXX((((1111))))
  3305.  
  3306.  
  3307.  
  3308.           -    Some implementations of _l_e_x allow a rule's action to
  3309.                begin on a separate line, if the rule's pattern has
  3310.                trailing whitespace:
  3311.  
  3312.                    %%
  3313.                    foo|bar<space here>
  3314.                      { foobar_action(); }
  3315.  
  3316.                _f_l_e_x does not support this feature.
  3317.  
  3318.           -    The _l_e_x %%%%rrrr (generate a Ratfor scanner) option is not
  3319.                supported.  It is not part of the POSIX specification.
  3320.  
  3321.           -    After a call to uuuunnnnppppuuuutttt(((()))),,,, _y_y_t_e_x_t is undefined until the
  3322.                next token is matched, unless the scanner was built
  3323.                using %%%%aaaarrrrrrrraaaayyyy.... This is not the case with _l_e_x or the
  3324.                POSIX specification.  The ----llll option does away with this
  3325.                incompatibility.
  3326.  
  3327.           -    The precedence of the {{{{}}}} (numeric range) operator is
  3328.                different.  The AT&T and POSIX specifiations of _l_e_x
  3329.                interpret "abc{1,3}" as "match one, two, or three
  3330.                occurrences of 'abc'", whereas _f_l_e_x interprets it as
  3331.                "match 'ab' followed by one, two, or three occurrences
  3332.                of 'c'".  The ----llll and --------ppppoooossssiiiixxxx----ccccoooommmmppppaaaatttt options do away
  3333.                with this incompatibility.
  3334.  
  3335.           -    The precedence of the ^^^^ operator is different.  _l_e_x
  3336.                interprets "^foo|bar" as "match either 'foo' at the
  3337.                beginning of a line, or 'bar' anywhere", whereas _f_l_e_x
  3338.                interprets it as "match either 'foo' or 'bar' if they
  3339.                come at the beginning of a line".  The latter is in
  3340.                agreement with the POSIX specification.
  3341.  
  3342.           -    The special table-size declarations such as %%%%aaaa
  3343.                supported by _l_e_x are not required by _f_l_e_x scanners;
  3344.                _f_l_e_x ignores them.
  3345.  
  3346.           -    The name FLEX_SCANNER is #define'd so scanners may be
  3347.                written for use with either _f_l_e_x or _l_e_x. Scanners also
  3348.                include YYYYYYYY____FFFFLLLLEEEEXXXX____MMMMAAAAJJJJOOOORRRR____VVVVEEEERRRRSSSSIIIIOOOONNNN and YYYYYYYY____FFFFLLLLEEEEXXXX____MMMMIIIINNNNOOOORRRR____VVVVEEEERRRRSSSSIIIIOOOONNNN
  3349.                indicating which version of _f_l_e_x generated the scanner
  3350.                (for example, for the 2.5 release, these defines would
  3351.                be 2 and 5 respectively).
  3352.  
  3353.           The following _f_l_e_x features are not included in _l_e_x or the
  3354.           POSIX specification:
  3355.  
  3356.               C++ scanners
  3357.               %option
  3358.               start condition scopes
  3359.               start condition stacks
  3360.  
  3361.  
  3362.  
  3363.      Page 51                                         (printed 10/3/02)
  3364.  
  3365.  
  3366.  
  3367.  
  3368.  
  3369.  
  3370.      FFFFLLLLEEEEXXXX((((1111))))             VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))              FFFFLLLLEEEEXXXX((((1111))))
  3371.  
  3372.  
  3373.  
  3374.               interactive/non-interactive scanners
  3375.               yy_scan_string() and friends
  3376.               yyterminate()
  3377.               yy_set_interactive()
  3378.               yy_set_bol()
  3379.               YY_AT_BOL()
  3380.               <<EOF>>
  3381.               <*>
  3382.               YY_DECL
  3383.               YY_START
  3384.               YY_USER_ACTION
  3385.               YY_USER_INIT
  3386.               #line directives
  3387.               %{}'s around actions
  3388.               multiple actions on a line
  3389.  
  3390.           plus almost all of the flex flags.  The last feature in the
  3391.           list refers to the fact that with _f_l_e_x you can put multiple
  3392.           actions on the same line, separated with semi-colons, while
  3393.           with _l_e_x, the following
  3394.  
  3395.               foo    handle_foo(); ++num_foos_seen;
  3396.  
  3397.           is (rather surprisingly) truncated to
  3398.  
  3399.               foo    handle_foo();
  3400.  
  3401.           _f_l_e_x does not truncate the action.  Actions that are not
  3402.           enclosed in braces are simply terminated at the end of the
  3403.           line.
  3404.  
  3405.      DDDDIIIIAAAAGGGGNNNNOOOOSSSSTTTTIIIICCCCSSSS
  3406.           _w_a_r_n_i_n_g, _r_u_l_e _c_a_n_n_o_t _b_e _m_a_t_c_h_e_d indicates that the given
  3407.           rule cannot be matched because it follows other rules that
  3408.           will always match the same text as it.  For example, in the
  3409.           following "foo" cannot be matched because it comes after an
  3410.           identifier "catch-all" rule:
  3411.  
  3412.               [a-z]+    got_identifier();
  3413.               foo       got_foo();
  3414.  
  3415.           Using RRRREEEEJJJJEEEECCCCTTTT in a scanner suppresses this warning.
  3416.  
  3417.           _w_a_r_n_i_n_g, ----ssss _o_p_t_i_o_n _g_i_v_e_n _b_u_t _d_e_f_a_u_l_t _r_u_l_e _c_a_n _b_e _m_a_t_c_h_e_d
  3418.           means that it is possible (perhaps only in a particular
  3419.           start condition) that the default rule (match any single
  3420.           character) is the only one that will match a particular
  3421.           input.  Since ----ssss was given, presumably this is not intended.
  3422.  
  3423.           _r_e_j_e_c_t__u_s_e_d__b_u_t__n_o_t__d_e_t_e_c_t_e_d _u_n_d_e_f_i_n_e_d or
  3424.           _y_y_m_o_r_e__u_s_e_d__b_u_t__n_o_t__d_e_t_e_c_t_e_d _u_n_d_e_f_i_n_e_d - These errors can
  3425.           occur at compile time.  They indicate that the scanner uses
  3426.  
  3427.  
  3428.  
  3429.      Page 52                                         (printed 10/3/02)
  3430.  
  3431.  
  3432.  
  3433.  
  3434.  
  3435.  
  3436.      FFFFLLLLEEEEXXXX((((1111))))             VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))              FFFFLLLLEEEEXXXX((((1111))))
  3437.  
  3438.  
  3439.  
  3440.           RRRREEEEJJJJEEEECCCCTTTT or yyyyyyyymmmmoooorrrreeee(((()))) but that _f_l_e_x failed to notice the fact,
  3441.           meaning that _f_l_e_x scanned the first two sections looking for
  3442.           occurrences of these actions and failed to find any, but
  3443.           somehow you snuck some in (via a #include file, for
  3444.           example).  Use %%%%ooooppppttttiiiioooonnnn rrrreeeejjjjeeeecccctttt or %%%%ooooppppttttiiiioooonnnn yyyyyyyymmmmoooorrrreeee to indicate
  3445.           to flex that you really do use these features.
  3446.  
  3447.           _f_l_e_x _s_c_a_n_n_e_r _j_a_m_m_e_d - a scanner compiled with ----ssss has
  3448.           encountered an input string which wasn't matched by any of
  3449.           its rules.  This error can also occur due to internal
  3450.           problems.
  3451.  
  3452.           _t_o_k_e_n _t_o_o _l_a_r_g_e, _e_x_c_e_e_d_s _Y_Y_L_M_A_X - your scanner uses %%%%aaaarrrrrrrraaaayyyy
  3453.           and one of its rules matched a string longer than the YYYYYYYYLLLLMMMMAAAAXXXX
  3454.           constant (8K bytes by default).  You can increase the value
  3455.           by #define'ing YYYYYYYYLLLLMMMMAAAAXXXX in the definitions section of your
  3456.           _f_l_e_x input.
  3457.  
  3458.           _s_c_a_n_n_e_r _r_e_q_u_i_r_e_s -_8 _f_l_a_g _t_o _u_s_e _t_h_e _c_h_a_r_a_c_t_e_r '_x' - Your
  3459.           scanner specification includes recognizing the 8-bit
  3460.           character '_x' and you did not specify the -8 flag, and your
  3461.           scanner defaulted to 7-bit because you used the ----CCCCffff or ----CCCCFFFF
  3462.           table compression options.  See the discussion of the ----7777
  3463.           flag for details.
  3464.  
  3465.           _f_l_e_x _s_c_a_n_n_e_r _p_u_s_h-_b_a_c_k _o_v_e_r_f_l_o_w - you used uuuunnnnppppuuuutttt(((()))) to push
  3466.           back so much text that the scanner's buffer could not hold
  3467.           both the pushed-back text and the current token in yyyyyyyytttteeeexxxxtttt....
  3468.           Ideally the scanner should dynamically resize the buffer in
  3469.           this case, but at present it does not.
  3470.  
  3471.           _i_n_p_u_t _b_u_f_f_e_r _o_v_e_r_f_l_o_w, _c_a_n'_t _e_n_l_a_r_g_e _b_u_f_f_e_r _b_e_c_a_u_s_e _s_c_a_n_n_e_r
  3472.           _u_s_e_s _R_E_J_E_C_T - the scanner was working on matching an
  3473.           extremely large token and needed to expand the input buffer.
  3474.           This doesn't work with scanners that use RRRREEEEJJJJEEEECCCCTTTT....
  3475.  
  3476.           _f_a_t_a_l _f_l_e_x _s_c_a_n_n_e_r _i_n_t_e_r_n_a_l _e_r_r_o_r--_e_n_d _o_f _b_u_f_f_e_r _m_i_s_s_e_d -
  3477.           This can occur in an scanner which is reentered after a
  3478.           long-jump has jumped out (or over) the scanner's activation
  3479.           frame.  Before reentering the scanner, use:
  3480.  
  3481.               yyrestart( yyin );
  3482.  
  3483.           or, as noted above, switch to using the C++ scanner class.
  3484.  
  3485.           _t_o_o _m_a_n_y _s_t_a_r_t _c_o_n_d_i_t_i_o_n_s _i_n <> you listed more start
  3486.           conditions in a <> construct than exist (so you must have
  3487.           listed at least one of them twice).
  3488.  
  3489.      FFFFIIIILLLLEEEESSSS
  3490.           ----llllffffllll library with which scanners must be linked.
  3491.  
  3492.  
  3493.  
  3494.  
  3495.      Page 53                                         (printed 10/3/02)
  3496.  
  3497.  
  3498.  
  3499.  
  3500.  
  3501.  
  3502.      FFFFLLLLEEEEXXXX((((1111))))             VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))              FFFFLLLLEEEEXXXX((((1111))))
  3503.  
  3504.  
  3505.  
  3506.           _l_e_x._y_y._c
  3507.                generated scanner (called _l_e_x_y_y._c on some systems).
  3508.  
  3509.           _l_e_x._y_y._c_c
  3510.                generated C++ scanner class, when using ----++++....
  3511.  
  3512.           <_F_l_e_x_L_e_x_e_r._h>
  3513.                header file defining the C++ scanner base class,
  3514.                FFFFlllleeeexxxxLLLLeeeexxxxeeeerrrr,,,, and its derived class, yyyyyyyyFFFFlllleeeexxxxLLLLeeeexxxxeeeerrrr....
  3515.  
  3516.           _f_l_e_x._s_k_l
  3517.                skeleton scanner.  This file is only used when building
  3518.                flex, not when flex executes.
  3519.  
  3520.           _l_e_x._b_a_c_k_u_p
  3521.                backing-up information for ----bbbb flag (called _l_e_x._b_c_k on
  3522.                some systems).
  3523.  
  3524.      DDDDEEEEFFFFIIIICCCCIIIIEEEENNNNCCCCIIIIEEEESSSS //// BBBBUUUUGGGGSSSS
  3525.           Some trailing context patterns cannot be properly matched
  3526.           and generate warning messages ("dangerous trailing
  3527.           context").  These are patterns where the ending of the first
  3528.           part of the rule matches the beginning of the second part,
  3529.           such as "zx*/xy*", where the 'x*' matches the 'x' at the
  3530.           beginning of the trailing context.  (Note that the POSIX
  3531.           draft states that the text matched by such patterns is
  3532.           undefined.)
  3533.  
  3534.           For some trailing context rules, parts which are actually
  3535.           fixed-length are not recognized as such, leading to the
  3536.           abovementioned performance loss.  In particular, parts using
  3537.           '|' or {n} (such as "foo{3}") are always considered
  3538.           variable-length.
  3539.  
  3540.           Combining trailing context with the special '|' action can
  3541.           result in _f_i_x_e_d trailing context being turned into the more
  3542.           expensive _v_a_r_i_a_b_l_e trailing context.  For example, in the
  3543.           following:
  3544.  
  3545.               %%
  3546.               abc      |
  3547.               xyz/def
  3548.  
  3549.  
  3550.           Use of uuuunnnnppppuuuutttt(((()))) invalidates yytext and yyleng, unless the
  3551.           %%%%aaaarrrrrrrraaaayyyy directive or the ----llll option has been used.
  3552.  
  3553.           Pattern-matching of NUL's is substantially slower than
  3554.           matching other characters.
  3555.  
  3556.           Dynamic resizing of the input buffer is slow, as it entails
  3557.           rescanning all the text matched so far by the current
  3558.  
  3559.  
  3560.  
  3561.      Page 54                                         (printed 10/3/02)
  3562.  
  3563.  
  3564.  
  3565.  
  3566.  
  3567.  
  3568.      FFFFLLLLEEEEXXXX((((1111))))             VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))              FFFFLLLLEEEEXXXX((((1111))))
  3569.  
  3570.  
  3571.  
  3572.           (generally huge) token.
  3573.  
  3574.           Due to both buffering of input and read-ahead, you cannot
  3575.           intermix calls to <stdio.h> routines, such as, for example,
  3576.           ggggeeeettttcccchhhhaaaarrrr(((()))),,,, with _f_l_e_x rules and expect it to work.  Call
  3577.           iiiinnnnppppuuuutttt(((()))) instead.
  3578.  
  3579.           The total table entries listed by the ----vvvv flag excludes the
  3580.           number of table entries needed to determine what rule has
  3581.           been matched.  The number of entries is equal to the number
  3582.           of DFA states if the scanner does not use RRRREEEEJJJJEEEECCCCTTTT,,,, and
  3583.           somewhat greater than the number of states if it does.
  3584.  
  3585.           RRRREEEEJJJJEEEECCCCTTTT cannot be used with the ----ffff or ----FFFF options.
  3586.  
  3587.           The _f_l_e_x internal algorithms need documentation.
  3588.  
  3589.      SSSSEEEEEEEE AAAALLLLSSSSOOOO
  3590.           lex(1), yacc(1), sed(1), awk(1).
  3591.  
  3592.           John Levine, Tony Mason, and Doug Brown, _L_e_x & _Y_a_c_c,
  3593.           O'Reilly and Associates.  Be sure to get the 2nd edition.
  3594.  
  3595.           M. E. Lesk and E. Schmidt, _L_E_X - _L_e_x_i_c_a_l _A_n_a_l_y_z_e_r _G_e_n_e_r_a_t_o_r
  3596.  
  3597.           Alfred Aho, Ravi Sethi and Jeffrey Ullman, _C_o_m_p_i_l_e_r_s:
  3598.           _P_r_i_n_c_i_p_l_e_s, _T_e_c_h_n_i_q_u_e_s _a_n_d _T_o_o_l_s, Addison-Wesley (1986).
  3599.           Describes the pattern-matching techniques used by _f_l_e_x
  3600.           (deterministic finite automata).
  3601.  
  3602.      AAAAUUUUTTTTHHHHOOOORRRR
  3603.           Vern Paxson, with the help of many ideas and much
  3604.           inspiration from Van Jacobson.  Original version by Jef
  3605.           Poskanzer.  The fast table representation is a partial
  3606.           implementation of a design done by Van Jacobson.  The
  3607.           implementation was done by Kevin Gong and Vern Paxson.
  3608.  
  3609.           Thanks to the many _f_l_e_x beta-testers, feedbackers, and
  3610.           contributors, especially Francois Pinard, Casey Leedom,
  3611.           Robert Abramovitz, Stan Adermann, Terry Allen, David
  3612.           Barker-Plummer, John Basrai, Neal Becker, Nelson H.F. Beebe,
  3613.           benson@odi.com, Karl Berry, Peter A. Bigot, Simon Blanchard,
  3614.           Keith Bostic, Frederic Brehm, Ian Brockbank, Kin Cho, Nick
  3615.           Christopher, Brian Clapper, J.T. Conklin, Jason Coughlin,
  3616.           Bill Cox, Nick Cropper, Dave Curtis, Scott David Daniels,
  3617.           Chris G. Demetriou, Theo Deraadt, Mike Donahue, Chuck
  3618.           Doucette, Tom Epperly, Leo Eskin, Chris Faylor, Chris
  3619.           Flatters, Jon Forrest, Jeffrey Friedl, Joe Gayda, Kaveh R.
  3620.           Ghazi, Wolfgang Glunz, Eric Goldman, Christopher M. Gould,
  3621.           Ulrich Grepel, Peer Griebel, Jan Hajic, Charles Hemphill,
  3622.           NORO Hideo, Jarkko Hietaniemi, Scott Hofmann, Jeff Honig,
  3623.           Dana Hudes, Eric Hughes, John Interrante, Ceriel Jacobs,
  3624.  
  3625.  
  3626.  
  3627.      Page 55                                         (printed 10/3/02)
  3628.  
  3629.  
  3630.  
  3631.  
  3632.  
  3633.  
  3634.      FFFFLLLLEEEEXXXX((((1111))))             VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))              FFFFLLLLEEEEXXXX((((1111))))
  3635.  
  3636.  
  3637.  
  3638.           Michal Jaegermann, Sakari Jalovaara, Jeffrey R. Jones, Henry
  3639.           Juengst, Klaus Kaempf, Jonathan I. Kamens, Terrence O Kane,
  3640.           Amir Katz, ken@ken.hilco.com, Kevin B. Kenny, Steve Kirsch,
  3641.           Winfried Koenig, Marq Kole, Ronald Lamprecht, Greg Lee,
  3642.           Rohan Lenard, Craig Leres, John Levine, Steve Liddle, David
  3643.           Loffredo, Mike Long, Mohamed el Lozy, Brian Madsen, Malte,
  3644.           Joe Marshall, Bengt Martensson, Chris Metcalf, Luke Mewburn,
  3645.           Jim Meyering, R. Alexander Milowski, Erik Naggum, G.T.
  3646.           Nicol, Landon Noll, James Nordby, Marc Nozell, Richard
  3647.           Ohnemus, Karsten Pahnke, Sven Panne, Roland Pesch, Walter
  3648.           Pelissero, Gaumond Pierre, Esmond Pitt, Jef Poskanzer, Joe
  3649.           Rahmeh, Jarmo Raiha, Frederic Raimbault, Pat Rankin, Rick
  3650.           Richardson, Kevin Rodgers, Kai Uwe Rommel, Jim Roskind,
  3651.           Alberto Santini, Andreas Scherer, Darrell Schiebel, Raf
  3652.           Schietekat, Doug Schmidt, Philippe Schnoebelen, Andreas
  3653.           Schwab, Larry Schwimmer, Alex Siegel, Eckehard Stolz, Jan-
  3654.           Erik Strvmquist, Mike Stump, Paul Stuart, Dave Tallman, Ian
  3655.           Lance Taylor, Chris Thewalt, Richard M. Timoney, Jodi Tsai,
  3656.           Paul Tuinenga, Gary Weik, Frank Whaley, Gerhard Wilhelms,
  3657.           Kent Williams, Ken Yap, Ron Zellar, Nathan Zelle, David
  3658.           Zuhn, and those whose names have slipped my marginal mail-
  3659.           archiving skills but whose contributions are appreciated all
  3660.           the same.
  3661.  
  3662.           Thanks to Keith Bostic, Jon Forrest, Noah Friedman, John
  3663.           Gilmore, Craig Leres, John Levine, Bob Mulcahy, G.T.  Nicol,
  3664.           Francois Pinard, Rich Salz, and Richard Stallman for help
  3665.           with various distribution headaches.
  3666.  
  3667.           Thanks to Esmond Pitt and Earle Horton for 8-bit character
  3668.           support; to Benson Margulies and Fred Burke for C++ support;
  3669.           to Kent Williams and Tom Epperly for C++ class support; to
  3670.           Ove Ewerlid for support of NUL's; and to Eric Hughes for
  3671.           support of multiple buffers.
  3672.  
  3673.           This work was primarily done when I was with the Real Time
  3674.           Systems Group at the Lawrence Berkeley Laboratory in
  3675.           Berkeley, CA.  Many thanks to all there for the support I
  3676.           received.
  3677.  
  3678.           Send comments to vern@ee.lbl.gov.
  3679.  
  3680.  
  3681.  
  3682.  
  3683.  
  3684.  
  3685.  
  3686.  
  3687.  
  3688.  
  3689.  
  3690.  
  3691.  
  3692.  
  3693.      Page 56                                         (printed 10/3/02)
  3694.  
  3695.  
  3696.  
  3697.